From 04e3ded4c28c0b559620609daaae7b939d776b61 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 15 Jun 2024 11:42:48 -0700 Subject: Add path. --- filesystem/src/filesystem.c | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'filesystem/src/filesystem.c') diff --git a/filesystem/src/filesystem.c b/filesystem/src/filesystem.c index f6bb693..b228e85 100644 --- a/filesystem/src/filesystem.c +++ b/filesystem/src/filesystem.c @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -54,42 +55,3 @@ cleanup: } return 0; } - -bool make_relative_path( - const char* filepath, const char* path, char* relative, - size_t relative_length) { - assert(filepath); - assert(path); - assert(relative); - - const size_t filepath_len = strlen(filepath); - const size_t path_len = strlen(path); - assert(filepath_len < relative_length); - assert(path_len < relative_length); - - // Handle empty filepath. - if (filepath_len == 0) { - memcpy(relative, path, path_len); - return true; - } - - // Search for the last / in the file path to get its parent directory. - assert(filepath_len > 0); - size_t tm_dir_len = 0; - for (tm_dir_len = strlen(filepath) - 1; tm_dir_len > 0; --tm_dir_len) { - if (filepath[tm_dir_len] == '/') { - break; - } - } - tm_dir_len++; // Preserve the backslash. - - // Copy the file path where the parent dir ends. - // Make sure there is enough space in the output. - if ((tm_dir_len + path_len + 1) >= relative_length) { - return false; - } - memcpy(relative, filepath, tm_dir_len); - memcpy(&relative[tm_dir_len], path, path_len); - - return true; -} -- cgit v1.2.3