summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/filesystem.c12
-rw-r--r--src/filesystem.h4
-rw-r--r--src/lilv_internal.h2
-rw-r--r--src/state.c8
4 files changed, 18 insertions, 8 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));
}