diff options
author | David Robillard <d@drobilla.net> | 2022-11-12 17:54:33 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-11-16 10:22:55 -0500 |
commit | de60d222d9b1ff7931b74ded75cd8e31d77d9bd9 (patch) | |
tree | 0faa5c28d695452b2cca0b74f477bde044ec134e | |
parent | 9d5c526e264e2fe13f8b579528da21b54c65ab9e (diff) | |
download | lilv-de60d222d9b1ff7931b74ded75cd8e31d77d9bd9.tar.gz lilv-de60d222d9b1ff7931b74ded75cd8e31d77d9bd9.tar.bz2 lilv-de60d222d9b1ff7931b74ded75cd8e31d77d9bd9.zip |
Use zix_path_filename()
-rw-r--r-- | src/filesystem.c | 22 | ||||
-rw-r--r-- | src/filesystem.h | 8 | ||||
-rw-r--r-- | src/state.c | 6 | ||||
-rw-r--r-- | test/test_filesystem.c | 23 |
4 files changed, 2 insertions, 57 deletions
diff --git a/src/filesystem.c b/src/filesystem.c index 2305c6d..a690338 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -69,28 +69,6 @@ lilv_path_parent(const char* path) } char* -lilv_path_filename(const char* path) -{ - const size_t path_len = strlen(path); - size_t last_sep = path_len; - for (size_t i = 0; i < path_len; ++i) { - if (lilv_is_dir_sep(path[i])) { - last_sep = i; - } - } - - if (last_sep >= path_len) { - return lilv_strdup(path); - } - - const size_t ret_len = path_len - last_sep; - char* const ret = (char*)calloc(ret_len + 1, 1); - - strncpy(ret, path + last_sep + 1, ret_len); - return ret; -} - -char* lilv_create_temporary_directory(const char* pattern) { char* const tmpdir = zix_temp_directory_path(NULL); diff --git a/src/filesystem.h b/src/filesystem.h index 5dbbdcf..5b355f1 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -16,14 +16,6 @@ char* lilv_path_parent(const char* path); /** - Return the filename component of `path` without any directories. - - Returns the empty string if `path` is the root path. -*/ -char* -lilv_path_filename(const char* path); - -/** Create a unique temporary directory. This is like lilv_create_temporary_directory_in(), except it creates the diff --git a/src/state.c b/src/state.c index d98b80b..8442949 100644 --- a/src/state.c +++ b/src/state.c @@ -315,12 +315,10 @@ abstract_path(LV2_State_Map_Path_Handle handle, const char* abs_path) } } else if (state->link_dir) { // New path outside state directory, make a link - char* const name = lilv_path_filename(real_path); + const ZixStringView name = zix_path_filename(real_path); // Find a free name in the (virtual) state directory - path = lilv_find_free_path(name, lilv_state_has_path, state); - - free(name); + path = lilv_find_free_path(name.data, lilv_state_has_path, state); } else { // No link directory, preserve absolute path path = lilv_strdup(abs_path); diff --git a/test/test_filesystem.c b/test/test_filesystem.c index 99e4f3c..6f3dc1e 100644 --- a/test/test_filesystem.c +++ b/test/test_filesystem.c @@ -53,34 +53,11 @@ test_path_parent(void) assert(equals(lilv_path_parent("a"), ".")); } -static void -test_path_filename(void) -{ - // Cases from cppreference.com for std::filesystem::path::filename - assert(equals(lilv_path_filename("/foo/bar.txt"), "bar.txt")); - assert(equals(lilv_path_filename("/foo/.bar"), ".bar")); - assert(equals(lilv_path_filename("/foo/bar/"), "")); - assert(equals(lilv_path_filename("/foo/."), ".")); - assert(equals(lilv_path_filename("/foo/.."), "..")); - assert(equals(lilv_path_filename("."), ".")); - assert(equals(lilv_path_filename(".."), "..")); - assert(equals(lilv_path_filename("/"), "")); - assert(equals(lilv_path_filename("//host"), "host")); - -#ifdef _WIN32 - assert(equals(lilv_path_filename("C:/foo/bar.txt"), "bar.txt")); - assert(equals(lilv_path_filename("C:\\foo\\bar.txt"), "bar.txt")); - assert(equals(lilv_path_filename("foo/bar.txt"), "bar.txt")); - assert(equals(lilv_path_filename("foo\\bar.txt"), "bar.txt")); -#endif -} - int main(void) { test_path_is_child(); test_path_parent(); - test_path_filename(); return 0; } |