diff options
-rw-r--r-- | src/filesystem.c | 12 | ||||
-rw-r--r-- | src/filesystem.h | 4 | ||||
-rw-r--r-- | src/lilv_internal.h | 2 | ||||
-rw-r--r-- | src/state.c | 8 | ||||
-rw-r--r-- | test/lilv_test_utils.c | 11 | ||||
-rw-r--r-- | test/test_state.c | 3 |
6 files changed, 21 insertions, 19 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index 0d840ec..f521179 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -423,6 +423,18 @@ lilv_file_size(const char* path) return buf.st_size; } +int +lilv_remove(const char* path) +{ +#ifdef _WIN32 + if (lilv_is_directory(path)) { + return !RemoveDirectory(path); + } +#endif + + return remove(path); +} + bool lilv_file_equals(const char* a_path, const char* b_path) { diff --git a/src/filesystem.h b/src/filesystem.h index f5ac35c..14f25d7 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -147,6 +147,10 @@ lilv_create_temporary_directory(const char* pattern); int lilv_create_directories(const char* dir_path); +/// Remove the file or empty directory at `path` +int +lilv_remove(const char* path); + /// Return true iff the given paths point to files with identical contents bool lilv_file_equals(const char* a_path, const char* b_path); diff --git a/src/lilv_internal.h b/src/lilv_internal.h index 212e41a..d603df7 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -39,8 +39,6 @@ extern "C" { # include <stdio.h> # define dlopen(path, flags) LoadLibrary(path) # define dlclose(lib) FreeLibrary((HMODULE)lib) -# define unlink(path) _unlink(path) -# define rmdir(path) _rmdir(path) # ifdef _MSC_VER # define __func__ __FUNCTION__ # ifndef snprintf diff --git a/src/state.c b/src/state.c index 3086ea6..474ddbe 100644 --- a/src/state.c +++ b/src/state.c @@ -30,10 +30,6 @@ #include "lv2/state/state.h" #include "lv2/urid/urid.h" -#ifndef _WIN32 -#include <unistd.h> -#endif - #include <assert.h> #include <errno.h> #include <stdbool.h> @@ -1252,7 +1248,7 @@ static void try_unlink(const char* state_dir, const char* path) { if (!strncmp(state_dir, path, strlen(state_dir))) { - if (lilv_path_exists(path) && unlink(path)) { + if (lilv_path_exists(path) && lilv_remove(path)) { LILV_ERRORF("Failed to remove %s (%s)\n", path, strerror(errno)); } } @@ -1329,7 +1325,7 @@ lilv_state_delete(LilvWorld* world, } } - if (rmdir(state->dir)) { + if (lilv_remove(state->dir)) { LILV_ERRORF("Failed to remove directory %s (%s)\n", state->dir, strerror(errno)); } diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c index def3eca..cfc5c4f 100644 --- a/test/lilv_test_utils.c +++ b/test/lilv_test_utils.c @@ -24,13 +24,6 @@ #include "lilv/lilv.h" #include "serd/serd.h" -#ifdef _WIN32 -# include <direct.h> -# define mkdir(path, flags) _mkdir(path) -#else -# include <unistd.h> -#endif - #include <errno.h> #include <stdbool.h> #include <stdint.h> @@ -153,11 +146,11 @@ void delete_bundle(LilvTestEnv* env) { if (env->test_content_path) { - unlink(env->test_content_path); + lilv_remove(env->test_content_path); } if (env->test_manifest_path) { - unlink(env->test_manifest_path); + lilv_remove(env->test_manifest_path); } if (env->test_bundle_path) { diff --git a/test/test_state.c b/test/test_state.c index acca4e9..5a2e5cb 100644 --- a/test/test_state.c +++ b/test/test_state.c @@ -32,7 +32,6 @@ # define mkdir(path, flags) _mkdir(path) #else # include <sys/stat.h> -# include <unistd.h> #endif #include <assert.h> @@ -561,7 +560,7 @@ main(void) lilv_state_free(fstate7); lilv_state_free(fstate72); - rmdir("state"); + lilv_remove("state"); // Free URI map for (size_t i = 0; i < n_uris; ++i) { |