summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/filesystem.c45
-rw-r--r--src/filesystem.h11
-rw-r--r--test/test_filesystem.c19
-rw-r--r--test/test_util.c3
4 files changed, 8 insertions, 70 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index 548111f..c0ad864 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -5,6 +5,7 @@
#include "lilv_config.h"
#include "lilv_internal.h"
+#include "zix/allocator.h"
#include "zix/filesystem.h"
#include "zix/path.h"
@@ -12,7 +13,6 @@
# include <direct.h>
# include <io.h>
# include <windows.h>
-# define mkdir(path, flags) _mkdir(path)
# define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#else
# include <dirent.h>
@@ -312,47 +312,14 @@ lilv_dir_for_each(const char* path,
}
char*
-lilv_create_temporary_directory_in(const char* pattern, const char* parent)
-{
-#ifdef _WIN32
- static const char chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- static const int n_chars = sizeof(chars) - 1;
-
- const size_t pattern_len = strlen(pattern);
- if (pattern_len < 7 || strcmp(pattern + pattern_len - 6, "XXXXXX")) {
- errno = EINVAL;
- return NULL;
- }
-
- char* const path_pattern = zix_path_join(NULL, parent, pattern);
- const size_t path_pattern_len = strlen(path_pattern);
- char* const suffix = path_pattern + path_pattern_len - 6;
-
- for (unsigned attempt = 0; attempt < 128; ++attempt) {
- for (unsigned i = 0; i < 6; ++i) {
- suffix[i] = chars[rand() % n_chars];
- }
-
- if (!mkdir(path_pattern, 0700)) {
- return path_pattern;
- }
- }
-
- return NULL;
-#else
- char* const path_pattern = zix_path_join(NULL, parent, pattern);
-
- return mkdtemp(path_pattern); // NOLINT (not a leak)
-#endif
-}
-
-char*
lilv_create_temporary_directory(const char* pattern)
{
- char* const tmpdir = zix_temp_directory_path(NULL);
- char* const result = lilv_create_temporary_directory_in(pattern, tmpdir);
+ char* const tmpdir = zix_temp_directory_path(NULL);
+ char* const path_pattern = zix_path_join(NULL, tmpdir, pattern);
+ char* const result = zix_create_temporary_directory(NULL, path_pattern);
- free(tmpdir);
+ zix_free(NULL, path_pattern);
+ zix_free(NULL, tmpdir);
return result;
}
diff --git a/src/filesystem.h b/src/filesystem.h
index 157b072..4d66e19 100644
--- a/src/filesystem.h
+++ b/src/filesystem.h
@@ -94,17 +94,6 @@ lilv_dir_for_each(const char* path,
void (*f)(const char* path, const char* name, void* data));
/**
- Create a unique temporary directory in a specific directory.
-
- The last six characters of `pattern` must be `XXXXXX` and will be replaced
- with random characters. This works roughly like mkdtemp, except the pattern
- should only be a directory name, not a full path. The created path will be
- a child of the given parent directory.
-*/
-char*
-lilv_create_temporary_directory_in(const char* pattern, const char* parent);
-
-/**
Create a unique temporary directory.
This is like lilv_create_temporary_directory_in(), except it creates the
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index 301a3d2..01ccd5d 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -265,24 +265,6 @@ test_dir_for_each(void)
free(temp_dir);
}
-static void
-test_create_temporary_directory(void)
-{
- char* const path1 = lilv_create_temporary_directory("lilvXXXXXX");
-
- assert(lilv_is_directory(path1));
-
- char* const path2 = lilv_create_temporary_directory("lilvXXXXXX");
-
- assert(strcmp(path1, path2));
- assert(lilv_is_directory(path2));
-
- assert(!zix_remove(path2));
- assert(!zix_remove(path1));
- free(path2);
- free(path1);
-}
-
int
main(void)
{
@@ -296,7 +278,6 @@ main(void)
test_copy_file();
test_flock();
test_dir_for_each();
- test_create_temporary_directory();
return 0;
}
diff --git a/test/test_util.c b/test/test_util.c
index c228b8f..f6f7feb 100644
--- a/test/test_util.c
+++ b/test/test_util.c
@@ -15,7 +15,8 @@
int
main(void)
{
- char* const dir = lilv_create_temporary_directory("lilv_test_util_XXXXXX");
+ char* const dir = lilv_create_temporary_directory("lilv_test_util_XXXXXX");
+
char* const a_path = zix_path_join(NULL, dir, "copy_a_XXXXXX");
char* const b_path = zix_path_join(NULL, dir, "copy_b_XXXXXX");