summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-11-12 17:54:12 -0500
committerDavid Robillard <d@drobilla.net>2022-11-16 10:22:55 -0500
commitff9f776a48cdca700468f9d5a93625979d77e745 (patch)
tree51134aef6fd007f8a0b803a16cbf1ed06117189c
parent67a33e70aa2b3f2f78742e773bac5ccb7be95c20 (diff)
downloadlilv-ff9f776a48cdca700468f9d5a93625979d77e745.tar.gz
lilv-ff9f776a48cdca700468f9d5a93625979d77e745.tar.bz2
lilv-ff9f776a48cdca700468f9d5a93625979d77e745.zip
Use zix_path_join()
-rw-r--r--src/filesystem.c57
-rw-r--r--src/filesystem.h13
-rw-r--r--src/node.c23
-rw-r--r--src/state.c43
-rw-r--r--src/util.c8
-rw-r--r--test/lilv_test_utils.c32
-rw-r--r--test/test_filesystem.c106
-rw-r--r--test/test_state.c84
-rw-r--r--test/test_util.c5
9 files changed, 136 insertions, 235 deletions
diff --git a/src/filesystem.c b/src/filesystem.c
index 7897920..d8f42f3 100644
--- a/src/filesystem.c
+++ b/src/filesystem.c
@@ -5,6 +5,8 @@
#include "lilv_config.h"
#include "lilv_internal.h"
+#include "zix/path.h"
+
#ifdef _WIN32
# include <direct.h>
# include <io.h>
@@ -107,22 +109,12 @@ lilv_path_absolute(const char* path)
}
char* cwd = getcwd(NULL, 0);
- char* abs_path = lilv_path_join(cwd, path);
+ char* abs_path = zix_path_join(NULL, cwd, path);
free(cwd);
return abs_path;
}
char*
-lilv_path_absolute_child(const char* path, const char* parent)
-{
- if (lilv_path_is_absolute(path)) {
- return lilv_strdup(path);
- }
-
- return lilv_path_join(parent, path);
-}
-
-char*
lilv_path_relative_to(const char* path, const char* base)
{
const size_t path_len = strlen(path);
@@ -223,41 +215,6 @@ lilv_path_filename(const char* path)
}
char*
-lilv_path_join(const char* a, const char* b)
-{
- if (!a) {
- return (b && b[0]) ? lilv_strdup(b) : NULL;
- }
-
- const size_t a_len = strlen(a);
- const size_t b_len = b ? strlen(b) : 0;
- const bool a_end_is_sep = a_len > 0 && lilv_is_dir_sep(a[a_len - 1]);
- const size_t pre_len = a_len - (a_end_is_sep ? 1 : 0);
- char* path = (char*)calloc(1, a_len + b_len + 2);
- memcpy(path, a, pre_len);
-
-#ifndef _WIN32
- path[pre_len] = '/';
-#else
- // Use forward slash if it seems that the input paths do
- const bool a_has_slash = strchr(a, '/');
- const bool b_has_slash = b && strchr(b, '/');
- if (a_has_slash || b_has_slash) {
- path[pre_len] = '/';
- } else {
- path[pre_len] = '\\';
- }
-#endif
-
- if (b) {
- memcpy(path + pre_len + 1,
- b + (lilv_is_dir_sep(b[0]) ? 1 : 0),
- lilv_is_dir_sep(b[0]) ? b_len - 1 : b_len);
- }
- return path;
-}
-
-char*
lilv_path_canonical(const char* path)
{
if (!path) {
@@ -269,7 +226,7 @@ lilv_path_canonical(const char* path)
GetFullPathName(path, MAX_PATH, out, NULL);
return out;
#else
- char* real_path = realpath(path, NULL);
+ char* real_path = realpath(path, NULL);
return real_path ? real_path : lilv_strdup(path);
#endif
}
@@ -377,7 +334,7 @@ lilv_dir_for_each(const char* path,
void (*f)(const char* path, const char* name, void* data))
{
#ifdef _WIN32
- char* pat = lilv_path_join(path, "*");
+ char* pat = zix_path_join(NULL, path, "*");
WIN32_FIND_DATA fd;
HANDLE fh = FindFirstFile(pat, &fd);
if (fh != INVALID_HANDLE_VALUE) {
@@ -415,7 +372,7 @@ lilv_create_temporary_directory_in(const char* pattern, const char* parent)
return NULL;
}
- char* const path_pattern = lilv_path_join(parent, pattern);
+ 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;
@@ -431,7 +388,7 @@ lilv_create_temporary_directory_in(const char* pattern, const char* parent)
return NULL;
#else
- char* const path_pattern = lilv_path_join(parent, pattern);
+ char* const path_pattern = zix_path_join(NULL, parent, pattern);
return mkdtemp(path_pattern); // NOLINT (not a leak)
#endif
diff --git a/src/filesystem.h b/src/filesystem.h
index 424afc6..db398f3 100644
--- a/src/filesystem.h
+++ b/src/filesystem.h
@@ -30,15 +30,6 @@ char*
lilv_path_absolute(const char* path);
/**
- Return `path` as an absolute path relative to `parent`.
-
- If `path` is absolute, an identical copy of it is returned. Otherwise, the
- returned path is relative to `parent`.
-*/
-char*
-lilv_path_absolute_child(const char* path, const char* parent);
-
-/**
Return `path` relative to `base` if possible.
If `path` is not within `base`, a copy is returned. Otherwise, an
@@ -64,10 +55,6 @@ lilv_path_parent(const char* path);
char*
lilv_path_filename(const char* path);
-/// Join path `a` and path `b` with a single directory separator between them
-char*
-lilv_path_join(const char* a, const char* b);
-
/**
Return `path` as a canonicalized absolute path.
diff --git a/src/node.c b/src/node.c
index 240daa2..d42ed4f 100644
--- a/src/node.c
+++ b/src/node.c
@@ -1,12 +1,15 @@
// Copyright 2007-2019 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "filesystem.h"
#include "lilv_internal.h"
#include "lilv/lilv.h"
#include "serd/serd.h"
#include "sord/sord.h"
+#include "zix/allocator.h"
+#include "zix/filesystem.h"
+#include "zix/path.h"
+#include "zix/string_view.h"
#include <math.h>
#include <stdbool.h>
@@ -147,13 +150,23 @@ lilv_new_uri(LilvWorld* world, const char* uri)
LilvNode*
lilv_new_file_uri(LilvWorld* world, const char* host, const char* path)
{
- char* abs_path = lilv_path_absolute(path);
- SerdNode s = serd_node_new_file_uri(
- (const uint8_t*)abs_path, (const uint8_t*)host, NULL, true);
+ SerdNode s = SERD_NODE_NULL;
+ if (zix_path_root_directory(path).length) {
+ s = serd_node_new_file_uri(
+ (const uint8_t*)path, (const uint8_t*)host, NULL, true);
+ } else {
+ char* const cwd = zix_current_path(NULL);
+ char* const abs_path = zix_path_join(NULL, cwd, path);
+
+ s = serd_node_new_file_uri(
+ (const uint8_t*)abs_path, (const uint8_t*)host, NULL, true);
+
+ zix_free(NULL, abs_path);
+ zix_free(NULL, cwd);
+ }
LilvNode* ret = lilv_node_new(world, LILV_VALUE_URI, (const char*)s.buf);
serd_node_free(&s);
- free(abs_path);
return ret;
}
diff --git a/src/state.c b/src/state.c
index d215c15..2adb7bc 100644
--- a/src/state.c
+++ b/src/state.c
@@ -8,7 +8,9 @@
#include "serd/serd.h"
#include "sord/sord.h"
#include "sratom/sratom.h"
+#include "zix/allocator.h"
#include "zix/filesystem.h"
+#include "zix/path.h"
#include "zix/tree.h"
#include "lv2/atom/atom.h"
@@ -251,7 +253,7 @@ make_path(LV2_State_Make_Path_Handle handle, const char* path)
LilvState* state = (LilvState*)handle;
lilv_create_directories(state->dir);
- return lilv_path_join(state->dir, path);
+ return zix_path_join(NULL, state->dir, path);
}
static char*
@@ -287,7 +289,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path)
"Error creating directory %s (%s)\n", state->copy_dir, strerror(st));
}
- char* cpath = lilv_path_join(state->copy_dir, path);
+ char* cpath = zix_path_join(NULL, state->copy_dir, path);
char* copy = lilv_get_latest_copy(real_path, cpath);
if (!copy || !lilv_file_equals(real_path, copy)) {
// No recent enough copy, make a new one
@@ -298,7 +300,7 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path)
}
}
free(real_path);
- free(cpath);
+ zix_free(NULL, cpath);
// Refer to the latest copy in plugin state
real_path = copy;
@@ -336,7 +338,7 @@ absolute_path(LV2_State_Map_Path_Handle handle, const char* state_path)
path = lilv_strdup(state_path);
} else if (state->dir) {
// Relative path inside state directory
- path = lilv_path_join(state->dir, state_path);
+ path = zix_path_join(NULL, state->dir, state_path);
} else {
// State has not been saved, unmap
path = lilv_strdup(lilv_state_rel2abs(state, state_path));
@@ -382,7 +384,7 @@ static char*
real_dir(const char* path)
{
char* abs_path = lilv_path_canonical(path);
- char* base = lilv_path_join(abs_path, NULL);
+ char* base = zix_path_join(NULL, abs_path, NULL);
free(abs_path);
return base;
}
@@ -560,7 +562,7 @@ set_state_dir_from_model(LilvState* state, const SordNode* graph)
const char* uri = (const char*)sord_node_get_string(graph);
char* path = lilv_file_uri_parse(uri, NULL);
- state->dir = lilv_path_join(path, NULL);
+ state->dir = zix_path_join(NULL, path, NULL);
free(path);
}
assert(!state->dir || lilv_path_is_absolute(state->dir));
@@ -580,7 +582,7 @@ new_state_from_model(LilvWorld* world,
// Allocate state
LilvState* const state = (LilvState*)calloc(1, sizeof(LilvState));
- state->dir = lilv_path_join(dir, NULL);
+ state->dir = dir ? zix_path_join(NULL, dir, NULL) : NULL;
state->atom_Path = map->map(map->handle, LV2_ATOM__Path);
state->uri = lilv_node_new_from_node(world, node);
@@ -745,10 +747,10 @@ lilv_state_new_from_file(LilvWorld* world,
char* dirname = lilv_path_parent(path);
char* real_path = lilv_path_canonical(dirname);
- char* dir_path = lilv_path_join(real_path, NULL);
+ char* dir_path = zix_path_join(NULL, real_path, NULL);
LilvState* state =
new_state_from_model(world, map, model, subject_node, dir_path);
- free(dir_path);
+ zix_free(NULL, dir_path);
free(real_path);
free(dirname);
@@ -1167,16 +1169,17 @@ lilv_state_make_links(const LilvState* state, const char* dir)
for (ZixTreeIter* i = zix_tree_begin(state->abs2rel);
i != zix_tree_end(state->abs2rel);
i = zix_tree_iter_next(i)) {
- const PathMap* pm = (const PathMap*)zix_tree_get(i);
+ const PathMap* const pm = (const PathMap*)zix_tree_get(i);
+ char* const path = zix_path_join(NULL, dir, pm->rel);
- char* path = lilv_path_absolute_child(pm->rel, dir);
if (lilv_path_is_child(pm->abs, state->copy_dir) &&
strcmp(state->copy_dir, dir)) {
// Link directly to snapshot in the copy directory
maybe_symlink(pm->abs, path);
} else if (!lilv_path_is_child(pm->abs, dir)) {
const char* link_dir = state->link_dir ? state->link_dir : dir;
- char* pat = lilv_path_absolute_child(pm->rel, link_dir);
+ char* pat = zix_path_join(NULL, link_dir, pm->rel);
+
if (!strcmp(dir, link_dir)) {
// Link directory is save directory, make link at exact path
remove(pat);
@@ -1219,12 +1222,12 @@ lilv_state_save(LilvWorld* world,
}
char* abs_dir = real_dir(dir);
- char* const path = lilv_path_join(abs_dir, filename);
+ char* const path = zix_path_join(NULL, abs_dir, filename);
FILE* fd = fopen(path, "w");
if (!fd) {
LILV_ERRORF("Failed to open %s (%s)\n", path, strerror(errno));
free(abs_dir);
- free(path);
+ zix_free(NULL, path);
return 4;
}
@@ -1240,7 +1243,7 @@ lilv_state_save(LilvWorld* world,
lilv_state_write(world, map, unmap, state, ttl, (const char*)node.buf, dir);
// Set saved dir and uri (FIXME: const violation)
- free(state->dir);
+ zix_free(NULL, state->dir);
lilv_node_free(state->uri);
((LilvState*)state)->dir = lilv_strdup(abs_dir);
((LilvState*)state)->uri = lilv_new_uri(world, (const char*)node.buf);
@@ -1252,15 +1255,15 @@ lilv_state_save(LilvWorld* world,
// Add entry to manifest
if (!ret) {
- char* const manifest = lilv_path_join(abs_dir, "manifest.ttl");
+ char* const manifest = zix_path_join(NULL, abs_dir, "manifest.ttl");
ret = add_state_to_manifest(world, state->plugin_uri, manifest, uri, path);
- free(manifest);
+ zix_free(NULL, manifest);
}
free(abs_dir);
- free(path);
+ zix_free(NULL, path);
return ret;
}
@@ -1372,9 +1375,9 @@ lilv_state_delete(LilvWorld* world, const LilvState* state)
i != zix_tree_end(state->abs2rel);
i = zix_tree_iter_next(i)) {
const PathMap* pm = (const PathMap*)zix_tree_get(i);
- char* path = lilv_path_join(state->dir, pm->rel);
+ char* path = zix_path_join(NULL, state->dir, pm->rel);
try_unlink(state->dir, path);
- free(path);
+ zix_free(NULL, path);
}
} else {
// State loaded from model, get paths from loaded properties
diff --git a/src/util.c b/src/util.c
index 8c7e445..bed1a3d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -6,6 +6,8 @@
#include "lilv/lilv.h"
#include "serd/serd.h"
+#include "zix/allocator.h"
+#include "zix/path.h"
#include <sys/stat.h>
@@ -237,13 +239,13 @@ static void
update_latest(const char* path, const char* name, void* data)
{
Latest* latest = (Latest*)data;
- char* entry_path = lilv_path_join(path, name);
+ char* entry_path = zix_path_join(NULL, path, name);
unsigned num = 0;
if (sscanf(entry_path, latest->pattern, &num) == 1) {
struct stat st;
if (!stat(entry_path, &st)) {
if (st.st_mtime >= latest->time) {
- free(latest->latest);
+ zix_free(NULL, latest->latest);
latest->latest = entry_path;
}
} else {
@@ -251,7 +253,7 @@ update_latest(const char* path, const char* name, void* data)
}
}
if (entry_path != latest->latest) {
- free(entry_path);
+ zix_free(NULL, entry_path);
}
}
diff --git a/test/lilv_test_utils.c b/test/lilv_test_utils.c
index 5fd2d6e..520b91a 100644
--- a/test/lilv_test_utils.c
+++ b/test/lilv_test_utils.c
@@ -4,10 +4,11 @@
#include "lilv_test_utils.h"
#include "../src/filesystem.h"
-#include "../src/lilv_internal.h"
#include "lilv/lilv.h"
#include "serd/serd.h"
+#include "zix/allocator.h"
+#include "zix/path.h"
#include <errno.h>
#include <stdbool.h>
@@ -32,10 +33,10 @@ lilv_test_env_new(void)
// Set custom LV2_PATH in build directory to only use test data
char* test_path = lilv_path_canonical(LILV_TEST_DIR);
- char* lv2_path = lilv_strjoin(test_path, "/lv2", NULL);
+ char* lv2_path = zix_path_join(NULL, test_path, "lv2");
LilvNode* path = lilv_new_string(world, lv2_path);
lilv_world_set_option(world, LILV_OPTION_LV2_PATH, path);
- free(lv2_path);
+ zix_free(NULL, lv2_path);
free(test_path);
lilv_node_free(path);
@@ -45,10 +46,10 @@ lilv_test_env_new(void)
void
lilv_test_env_free(LilvTestEnv* env)
{
- free(env->test_content_path);
- free(env->test_manifest_path);
+ zix_free(NULL, env->test_content_path);
+ zix_free(NULL, env->test_manifest_path);
lilv_node_free(env->test_bundle_uri);
- free(env->test_bundle_path);
+ zix_free(NULL, env->test_bundle_path);
lilv_node_free(env->plugin2_uri);
lilv_node_free(env->plugin1_uri);
lilv_world_free(env->world);
@@ -63,11 +64,11 @@ create_bundle(LilvTestEnv* env,
{
{
char* const test_dir = lilv_path_canonical(LILV_TEST_DIR);
- char* const bundle_dir = lilv_path_join(test_dir, name);
+ char* const bundle_dir = zix_path_join(NULL, test_dir, name);
- env->test_bundle_path = lilv_path_join(bundle_dir, "");
+ env->test_bundle_path = zix_path_join(NULL, bundle_dir, "");
- lilv_free(bundle_dir);
+ zix_free(NULL, bundle_dir);
lilv_free(test_dir);
}
@@ -83,9 +84,12 @@ create_bundle(LilvTestEnv* env,
(const uint8_t*)env->test_bundle_path, NULL, NULL, true);
env->test_bundle_uri = lilv_new_uri(env->world, (const char*)s.buf);
+
env->test_manifest_path =
- lilv_path_join(env->test_bundle_path, "manifest.ttl");
- env->test_content_path = lilv_path_join(env->test_bundle_path, "plugin.ttl");
+ zix_path_join(NULL, env->test_bundle_path, "manifest.ttl");
+
+ env->test_content_path =
+ zix_path_join(NULL, env->test_bundle_path, "plugin.ttl");
serd_node_free(&s);
@@ -148,10 +152,10 @@ delete_bundle(LilvTestEnv* env)
remove(env->test_bundle_path);
}
- free(env->test_content_path);
- free(env->test_manifest_path);
+ zix_free(NULL, env->test_content_path);
+ zix_free(NULL, env->test_manifest_path);
lilv_node_free(env->test_bundle_uri);
- free(env->test_bundle_path);
+ zix_free(NULL, env->test_bundle_path);
env->test_content_path = NULL;
env->test_manifest_path = NULL;
diff --git a/test/test_filesystem.c b/test/test_filesystem.c
index a0e3bc8..dc4fd27 100644
--- a/test/test_filesystem.c
+++ b/test/test_filesystem.c
@@ -8,6 +8,7 @@
#include "../src/filesystem.h"
#include "zix/filesystem.h"
+#include "zix/path.h"
#include <assert.h>
#include <errno.h>
@@ -89,8 +90,8 @@ test_path_absolute(void)
const char* const long_path = "a/b/c";
char* const cwd = lilv_path_current();
- char* const expected_short = lilv_path_join(cwd, short_path);
- char* const expected_long = lilv_path_join(cwd, long_path);
+ char* const expected_short = zix_path_join(NULL, cwd, short_path);
+ char* const expected_long = zix_path_join(NULL, cwd, long_path);
assert(equals(lilv_path_absolute(short_path), expected_short));
assert(equals(lilv_path_absolute(long_path), expected_long));
@@ -101,24 +102,6 @@ test_path_absolute(void)
}
static void
-test_path_absolute_child(void)
-{
- const char* const parent = "/parent";
- const char* const short_path = "a";
- const char* const long_path = "a/b/c";
-
- char* const expected_short = lilv_path_join(parent, short_path);
- char* const expected_long = lilv_path_join(parent, long_path);
-
- assert(equals(lilv_path_absolute_child(short_path, parent), expected_short));
-
- assert(equals(lilv_path_absolute_child(long_path, parent), expected_long));
-
- free(expected_long);
- free(expected_short);
-}
-
-static void
test_path_relative_to(void)
{
assert(equals(lilv_path_relative_to("/a/b", "/a/"), "b"));
@@ -180,63 +163,10 @@ test_path_filename(void)
}
static void
-test_path_join(void)
-{
- assert(lilv_path_join(NULL, NULL) == NULL);
- assert(lilv_path_join(NULL, "") == NULL);
-
-#ifdef _WIN32
- assert(equals(lilv_path_join("", NULL), "\\"));
- assert(equals(lilv_path_join("", ""), "\\"));
- assert(equals(lilv_path_join("a", ""), "a\\"));
- assert(equals(lilv_path_join("a", NULL), "a\\"));
- assert(equals(lilv_path_join("a", "b"), "a\\b"));
-#else
- assert(equals(lilv_path_join("", NULL), "/"));
- assert(equals(lilv_path_join("", ""), "/"));
- assert(equals(lilv_path_join("a", ""), "a/"));
- assert(equals(lilv_path_join("a", NULL), "a/"));
- assert(equals(lilv_path_join("a", "b"), "a/b"));
-#endif
-
- assert(equals(lilv_path_join("/a", ""), "/a/"));
- assert(equals(lilv_path_join("/a/b", ""), "/a/b/"));
- assert(equals(lilv_path_join("/a/", ""), "/a/"));
- assert(equals(lilv_path_join("/a/b/", ""), "/a/b/"));
- assert(equals(lilv_path_join("a/b", ""), "a/b/"));
- assert(equals(lilv_path_join("a/", ""), "a/"));
- assert(equals(lilv_path_join("a/b/", ""), "a/b/"));
-
- assert(equals(lilv_path_join("/a", NULL), "/a/"));
- assert(equals(lilv_path_join("/a/b", NULL), "/a/b/"));
- assert(equals(lilv_path_join("/a/", NULL), "/a/"));
- assert(equals(lilv_path_join("/a/b/", NULL), "/a/b/"));
- assert(equals(lilv_path_join("a/b", NULL), "a/b/"));
- assert(equals(lilv_path_join("a/", NULL), "a/"));
- assert(equals(lilv_path_join("a/b/", NULL), "a/b/"));
-
- assert(equals(lilv_path_join("/a", "b"), "/a/b"));
- assert(equals(lilv_path_join("/a/", "b"), "/a/b"));
- assert(equals(lilv_path_join("a/", "b"), "a/b"));
-
- assert(equals(lilv_path_join("/a", "b/"), "/a/b/"));
- assert(equals(lilv_path_join("/a/", "b/"), "/a/b/"));
- assert(equals(lilv_path_join("a", "b/"), "a/b/"));
- assert(equals(lilv_path_join("a/", "b/"), "a/b/"));
-
-#ifdef _WIN32
- assert(equals(lilv_path_join("C:/a", "b"), "C:/a/b"));
- assert(equals(lilv_path_join("C:\\a", "b"), "C:\\a\\b"));
- assert(equals(lilv_path_join("C:/a", "b/"), "C:/a/b/"));
- assert(equals(lilv_path_join("C:\\a", "b\\"), "C:\\a\\b\\"));
-#endif
-}
-
-static void
test_path_canonical(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = lilv_path_join(temp_dir, "lilv_test_file");
+ char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
FILE* f = fopen(file_path, "w");
fprintf(f, "test\n");
@@ -245,7 +175,7 @@ test_path_canonical(void)
#ifndef _WIN32
// Test symlink resolution
- char* const link_path = lilv_path_join(temp_dir, "lilv_test_link");
+ char* const link_path = zix_path_join(NULL, temp_dir, "lilv_test_link");
assert(!lilv_symlink(file_path, link_path));
@@ -262,7 +192,7 @@ test_path_canonical(void)
// Test dot segment resolution
- char* const parent_dir_1 = lilv_path_join(temp_dir, "..");
+ char* const parent_dir_1 = zix_path_join(NULL, temp_dir, "..");
char* const parent_dir_2 = lilv_path_parent(temp_dir);
char* const real_parent_dir_1 = lilv_path_canonical(parent_dir_1);
char* const real_parent_dir_2 = lilv_path_canonical(parent_dir_2);
@@ -286,7 +216,7 @@ static void
test_is_directory(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = lilv_path_join(temp_dir, "lilv_test_file");
+ char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
assert(lilv_is_directory(temp_dir));
assert(!lilv_is_directory(file_path)); // Nonexistent
@@ -308,8 +238,8 @@ static void
test_copy_file(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = lilv_path_join(temp_dir, "lilv_test_file");
- char* const copy_path = lilv_path_join(temp_dir, "lilv_test_copy");
+ char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
+ char* const copy_path = zix_path_join(NULL, temp_dir, "lilv_test_copy");
FILE* f = fopen(file_path, "w");
fprintf(f, "test\n");
@@ -344,7 +274,7 @@ static void
test_flock(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const file_path = lilv_path_join(temp_dir, "lilv_test_file");
+ char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
FILE* const f1 = fopen(file_path, "w");
FILE* const f2 = fopen(file_path, "w");
@@ -383,8 +313,8 @@ static void
test_dir_for_each(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const path1 = lilv_path_join(temp_dir, "lilv_test_1");
- char* const path2 = lilv_path_join(temp_dir, "lilv_test_2");
+ char* const path1 = zix_path_join(NULL, temp_dir, "lilv_test_1");
+ char* const path2 = zix_path_join(NULL, temp_dir, "lilv_test_2");
FILE* const f1 = fopen(path1, "w");
FILE* const f2 = fopen(path2, "w");
@@ -438,14 +368,14 @@ test_create_directories(void)
assert(lilv_is_directory(temp_dir));
- char* const child_dir = lilv_path_join(temp_dir, "child");
- char* const grandchild_dir = lilv_path_join(child_dir, "grandchild");
+ char* const child_dir = zix_path_join(NULL, temp_dir, "child");
+ char* const grandchild_dir = zix_path_join(NULL, child_dir, "grandchild");
assert(!lilv_create_directories(grandchild_dir));
assert(lilv_is_directory(grandchild_dir));
assert(lilv_is_directory(child_dir));
- char* const file_path = lilv_path_join(temp_dir, "lilv_test_file");
+ char* const file_path = zix_path_join(NULL, temp_dir, "lilv_test_file");
FILE* const f = fopen(file_path, "w");
fprintf(f, "test\n");
@@ -467,8 +397,8 @@ static void
test_file_equals(void)
{
char* const temp_dir = lilv_create_temporary_directory("lilvXXXXXX");
- char* const path1 = lilv_path_join(temp_dir, "lilv_test_1");
- char* const path2 = lilv_path_join(temp_dir, "lilv_test_2");
+ char* const path1 = zix_path_join(NULL, temp_dir, "lilv_test_1");
+ char* const path2 = zix_path_join(NULL, temp_dir, "lilv_test_2");
FILE* const f1 = fopen(path1, "w");
FILE* const f2 = fopen(path2, "w");
@@ -502,11 +432,9 @@ main(void)
test_path_is_child();
test_path_current();
test_path_absolute();
- test_path_absolute_child();
test_path_relative_to();
test_path_parent();
test_path_filename();
- test_path_join();
test_path_canonical();
test_is_directory();
test_copy_file();
diff --git a/test/test_state.c b/test/test_state.c
index 524a495..97567a2 100644
--- a/test/test_state.c
+++ b/test/test_state.c
@@ -13,7 +13,9 @@
#include "lv2/state/state.h"
#include "lv2/urid/urid.h"
#include "serd/serd.h"
+#include "zix/allocator.h"
#include "zix/filesystem.h"
+#include "zix/path.h"
#ifdef _WIN32
# include <direct.h>
@@ -117,10 +119,10 @@ create_test_directories(void)
resolve it here so that path comparisons in tests work. */
dirs.top = lilv_path_canonical(top);
- dirs.shared = lilv_path_join(dirs.top, "shared");
- dirs.scratch = lilv_path_join(dirs.shared, "scratch");
- dirs.copy = lilv_path_join(dirs.shared, "copy");
- dirs.link = lilv_path_join(dirs.shared, "link");
+ dirs.shared = zix_path_join(NULL, dirs.top, "shared");
+ dirs.scratch = zix_path_join(NULL, dirs.shared, "scratch");
+ dirs.copy = zix_path_join(NULL, dirs.shared, "copy");
+ dirs.link = zix_path_join(NULL, dirs.shared, "link");
assert(!mkdir(dirs.shared, 0700));
assert(!mkdir(dirs.scratch, 0700));
@@ -145,7 +147,7 @@ remove_file(const char* path, const char* name, void* data)
{
(void)data;
- char* const full_path = lilv_path_join(path, name);
+ char* const full_path = zix_path_join(NULL, path, name);
assert(!lilv_remove(full_path));
free(full_path);
}
@@ -163,10 +165,10 @@ cleanup_test_directories(const TestDirectories dirs)
assert(!lilv_remove(dirs.shared));
assert(!lilv_remove(dirs.top));
- free(dirs.link);
- free(dirs.copy);
- free(dirs.scratch);
- free(dirs.shared);
+ zix_free(NULL, dirs.link);
+ zix_free(NULL, dirs.copy);
+ zix_free(NULL, dirs.scratch);
+ zix_free(NULL, dirs.shared);
free(dirs.top);
}
@@ -227,7 +229,7 @@ make_scratch_path(LV2_State_Make_Path_Handle handle, const char* path)
{
TestDirectories* dirs = (TestDirectories*)handle;
- return lilv_path_join(dirs->scratch, path);
+ return zix_path_join(NULL, dirs->scratch, path);
}
static const LilvPlugin*
@@ -585,11 +587,11 @@ test_to_files(void)
assert(ctx->out == 1.0);
// Check that the test plugin has made its recording scratch file
- char* const recfile_path = lilv_path_join(dirs.scratch, "recfile");
+ char* const recfile_path = zix_path_join(NULL, dirs.scratch, "recfile");
assert(zix_file_type(recfile_path) == ZIX_FILE_TYPE_REGULAR);
// Get state
- char* const bundle_1_path = lilv_path_join(dirs.top, "state1.lv2");
+ char* const bundle_1_path = zix_path_join(NULL, dirs.top, "state1.lv2");
LilvState* const state_1 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_1_path);
@@ -597,7 +599,7 @@ test_to_files(void)
assert(lilv_state_get_num_properties(state_1) == 10);
// Check that a snapshop of the recfile was created
- char* const recfile_copy_1 = lilv_path_join(dirs.copy, "recfile");
+ char* const recfile_copy_1 = zix_path_join(NULL, dirs.copy, "recfile");
assert(zix_file_type(recfile_copy_1) == ZIX_FILE_TYPE_REGULAR);
// Save state to a bundle
@@ -610,14 +612,15 @@ test_to_files(void)
"state.ttl"));
// Check that a manifest exists
- char* const manifest_path = lilv_path_join(bundle_1_path, "manifest.ttl");
+ char* const manifest_path =
+ zix_path_join(NULL, bundle_1_path, "manifest.ttl");
assert(zix_file_type(manifest_path) == ZIX_FILE_TYPE_REGULAR);
// Check that the expected statements are in the manifest file
assert(count_statements(manifest_path) == 3);
// Check that a link to the recfile exists in the saved bundle
- char* const recfile_link_1 = lilv_path_join(bundle_1_path, "recfile");
+ char* const recfile_link_1 = zix_path_join(NULL, bundle_1_path, "recfile");
assert(zix_file_type(recfile_link_1) == ZIX_FILE_TYPE_REGULAR);
#ifndef _WIN32
assert(zix_symlink_type(recfile_link_1) == ZIX_FILE_TYPE_SYMLINK);
@@ -630,7 +633,7 @@ test_to_files(void)
lilv_instance_run(instance, 2);
// Get updated state
- char* const bundle_2_path = lilv_path_join(dirs.top, "state2.lv2");
+ char* const bundle_2_path = zix_path_join(NULL, dirs.top, "state2.lv2");
LilvState* const state_2 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_2_path);
@@ -644,11 +647,11 @@ test_to_files(void)
"state.ttl"));
// Check that a new snapshop of the recfile was created
- char* const recfile_copy_2 = lilv_path_join(dirs.copy, "recfile.2");
+ char* const recfile_copy_2 = zix_path_join(NULL, dirs.copy, "recfile.2");
assert(zix_file_type(recfile_copy_2) == ZIX_FILE_TYPE_REGULAR);
// Check that a link to the recfile exists in the updated bundle
- char* const recfile_link_2 = lilv_path_join(bundle_2_path, "recfile");
+ char* const recfile_link_2 = zix_path_join(NULL, bundle_2_path, "recfile");
assert(zix_file_type(recfile_link_2) == ZIX_FILE_TYPE_REGULAR);
#ifndef _WIN32
assert(zix_symlink_type(recfile_link_2) == ZIX_FILE_TYPE_SYMLINK);
@@ -664,16 +667,16 @@ test_to_files(void)
assert(!lilv_remove(bundle_1_path));
cleanup_test_directories(dirs);
- free(recfile_link_2);
- free(recfile_copy_2);
+ zix_free(NULL, recfile_link_2);
+ zix_free(NULL, recfile_copy_2);
lilv_state_free(state_2);
- free(bundle_2_path);
- free(recfile_link_1);
- free(manifest_path);
- free(recfile_copy_1);
+ zix_free(NULL, bundle_2_path);
+ zix_free(NULL, recfile_link_1);
+ zix_free(NULL, manifest_path);
+ zix_free(NULL, recfile_copy_1);
lilv_state_free(state_1);
- free(bundle_1_path);
- free(recfile_path);
+ zix_free(NULL, bundle_1_path);
+ zix_free(NULL, recfile_path);
test_context_free(ctx);
}
@@ -696,7 +699,7 @@ test_multi_save(void)
assert(instance);
// Get state
- char* const bundle_1_path = lilv_path_join(dirs.top, "state1.lv2");
+ char* const bundle_1_path = zix_path_join(NULL, dirs.top, "state1.lv2");
LilvState* const state_1 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_1_path);
@@ -710,11 +713,12 @@ test_multi_save(void)
"state.ttl"));
// Check that a manifest exists
- char* const manifest_path = lilv_path_join(bundle_1_path, "manifest.ttl");
+ char* const manifest_path =
+ zix_path_join(NULL, bundle_1_path, "manifest.ttl");
assert(zix_file_type(manifest_path) == ZIX_FILE_TYPE_REGULAR);
// Check that the state file exists
- char* const state_path = lilv_path_join(bundle_1_path, "state.ttl");
+ char* const state_path = zix_path_join(NULL, bundle_1_path, "state.ttl");
assert(zix_file_type(state_path) == ZIX_FILE_TYPE_REGULAR);
// Check that the expected statements are in the files
@@ -776,7 +780,7 @@ test_files_round_trip(void)
assert(ctx->out == 1.0);
// Save first state to a bundle
- char* const bundle_1_1_path = lilv_path_join(dirs.top, "state1_1.lv2");
+ char* const bundle_1_1_path = zix_path_join(NULL, dirs.top, "state1_1.lv2");
LilvState* const state_1_1 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_1_1_path);
@@ -789,7 +793,7 @@ test_files_round_trip(void)
"state.ttl"));
// Save first state to another bundle
- char* const bundle_1_2_path = lilv_path_join(dirs.top, "state1_2.lv2");
+ char* const bundle_1_2_path = zix_path_join(NULL, dirs.top, "state1_2.lv2");
LilvState* const state_1_2 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_1_2_path);
@@ -802,8 +806,10 @@ test_files_round_trip(void)
"state.ttl"));
// Load both first state bundles and check that the results are equal
- char* const state_1_1_path = lilv_path_join(bundle_1_1_path, "state.ttl");
- char* const state_1_2_path = lilv_path_join(bundle_1_2_path, "state.ttl");
+ char* const state_1_1_path =
+ zix_path_join(NULL, bundle_1_1_path, "state.ttl");
+ char* const state_1_2_path =
+ zix_path_join(NULL, bundle_1_2_path, "state.ttl");
LilvState* state_1_1_loaded =
lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_1_1_path);
@@ -819,7 +825,7 @@ test_files_round_trip(void)
lilv_instance_run(instance, 2);
// Save updated state to a bundle
- char* const bundle_2_path = lilv_path_join(dirs.top, "state2.lv2");
+ char* const bundle_2_path = zix_path_join(NULL, dirs.top, "state2.lv2");
LilvState* const state_2 =
state_from_instance(plugin, instance, ctx, &dirs, bundle_2_path);
@@ -832,7 +838,7 @@ test_files_round_trip(void)
"state.ttl"));
// Load updated state bundle and check that it differs from the others
- char* const state_2_path = lilv_path_join(bundle_2_path, "state.ttl");
+ char* const state_2_path = zix_path_join(NULL, bundle_2_path, "state.ttl");
LilvState* state_2_loaded =
lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_2_path);
@@ -894,7 +900,7 @@ test_world_round_trip(void)
assert(ctx->out == 1.0);
// Save state to a bundle
- char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/");
+ char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/");
LilvState* const start_state =
state_from_instance(plugin, instance, ctx, &dirs, bundle_path);
@@ -959,7 +965,7 @@ test_label_round_trip(void)
lilv_state_set_label(state, "Monopoly on violence");
// Save to a bundle
- char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/");
+ char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/");
assert(!lilv_state_save(ctx->env->world,
&ctx->map,
&ctx->unmap,
@@ -969,7 +975,7 @@ test_label_round_trip(void)
"state.ttl"));
// Load bundle and check the label and that the states are equal
- char* const state_path = lilv_path_join(bundle_path, "state.ttl");
+ char* const state_path = zix_path_join(NULL, bundle_path, "state.ttl");
LilvState* const loaded =
lilv_state_new_from_file(ctx->env->world, &ctx->map, NULL, state_path);
@@ -1046,7 +1052,7 @@ test_delete(void)
assert(ctx->out == 1.0);
// Save state to a bundle
- char* const bundle_path = lilv_path_join(dirs.top, "state.lv2/");
+ char* const bundle_path = zix_path_join(NULL, dirs.top, "state.lv2/");
LilvState* const state =
state_from_instance(plugin, instance, ctx, &dirs, bundle_path);
diff --git a/test/test_util.c b/test/test_util.c
index 6eaf3e5..f8fcd7f 100644
--- a/test/test_util.c
+++ b/test/test_util.c
@@ -6,6 +6,7 @@
#include "../src/filesystem.h"
#include "lilv/lilv.h"
+#include "zix/path.h"
#include <assert.h>
#include <stdio.h>
@@ -16,8 +17,8 @@ main(void)
assert(!lilv_path_canonical(NULL));
char* const dir = lilv_create_temporary_directory("lilv_test_util_XXXXXX");
- char* const a_path = lilv_path_join(dir, "copy_a_XXXXXX");
- char* const b_path = lilv_path_join(dir, "copy_b_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");
FILE* const fa = fopen(a_path, "w");
FILE* const fb = fopen(b_path, "w");