From 2511f17ba30930668c5428420e7dad8c8879425e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Mar 2024 09:55:10 -0400 Subject: Fix test suite when TMPDIR has no trailing slash --- test/test_plugin.lv2/meson.build | 2 +- test/test_plugin.lv2/test_plugin.c | 50 ++++++-------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-) (limited to 'test/test_plugin.lv2') diff --git a/test/test_plugin.lv2/meson.build b/test/test_plugin.lv2/meson.build index 9b74245..e6c54cf 100644 --- a/test/test_plugin.lv2/meson.build +++ b/test/test_plugin.lv2/meson.build @@ -5,7 +5,7 @@ module = shared_module( 'test_plugin', files('test_plugin.c'), c_args: c_suppressions, - dependencies: lv2_dep, + dependencies: [lv2_dep, zix_dep], gnu_symbol_visibility: 'hidden', name_prefix: '', ) diff --git a/test/test_plugin.lv2/test_plugin.c b/test/test_plugin.lv2/test_plugin.c index cb89136..124f64c 100644 --- a/test/test_plugin.lv2/test_plugin.c +++ b/test/test_plugin.lv2/test_plugin.c @@ -5,11 +5,8 @@ #include "lv2/core/lv2.h" #include "lv2/state/state.h" #include "lv2/urid/urid.h" - -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include -#endif +#include "zix/filesystem.h" +#include "zix/path.h" #include #include @@ -37,35 +34,6 @@ typedef struct { unsigned num_runs; } Test; -static char* -temp_directory_path(void) -{ -#ifdef _WIN32 - const DWORD len = GetTempPath(0, NULL); - char* const buf = (char*)calloc(len, 1); - if (GetTempPath(len, buf) == 0) { - free(buf); - return NULL; - } - - return buf; -#else - const char* const tmpdir = getenv("TMPDIR"); - if (tmpdir) { - const size_t tmpdir_len = strlen(tmpdir); - char* const result = (char*)calloc(tmpdir_len + 1, 1); - - memcpy(result, tmpdir, tmpdir_len + 1); - return result; - } - - char* const result = (char*)calloc(6, 1); - - memcpy(result, "/tmp/", 6); - return result; -#endif -} - static void cleanup(LV2_Handle instance) { @@ -116,7 +84,7 @@ instantiate(const LV2_Descriptor* descriptor, return NULL; } - test->tmp_dir_path = temp_directory_path(); + test->tmp_dir_path = zix_temp_directory_path(NULL); LV2_State_Make_Path* make_path = NULL; @@ -284,14 +252,10 @@ save(LV2_Handle instance, LV2_STATE_IS_POD | LV2_STATE_IS_PORTABLE); if (map_path) { - const char* const file_name = "temp_file.txt"; - const size_t file_name_len = strlen(file_name); - const size_t dir_path_len = strlen(plugin->tmp_dir_path); - char* const tmp_file_path = - (char*)calloc(dir_path_len + file_name_len + 1, 1); - - memcpy(tmp_file_path, plugin->tmp_dir_path, dir_path_len); - memcpy(tmp_file_path + dir_path_len, file_name, file_name_len + 1); + const char* const file_name = "temp_file.txt"; + + char* const tmp_file_path = + zix_path_join(NULL, plugin->tmp_dir_path, file_name); FILE* file = fopen(tmp_file_path, "w"); if (!file) { -- cgit v1.2.1