diff --git a/src/filesystem/file.c b/src/filesystem/file.c index 1c62e2c..7d7f5e4 100644 --- a/src/filesystem/file.c +++ b/src/filesystem/file.c @@ -46,4 +46,5 @@ Result(void) file_seek(FILE* f, i64 offset, SeekOrigin origin){ "Can't seek (offset: " IFWIN("%lli", "%li") ", origin: %i) in file: %s", offset, origin, strerror(errno)); } + return RESULT_VOID; } \ No newline at end of file diff --git a/src/filesystem/path.c b/src/filesystem/path.c index 5221ecc..9691111 100644 --- a/src/filesystem/path.c +++ b/src/filesystem/path.c @@ -1,8 +1,16 @@ #include "tlibc/filesystem.h" str path_dirname(str path){ - i32 sepIndex = str_seekCharReverse(path, path_sep, 0); - if(sepIndex <= 0) + if(path.size == 0) + return path; + + // remove trailing slash (name/) + if(path.data[path.size - 1] == path_sep){ + path.size -= 1; + } + + i32 sepIndex = str_seekCharReverse(path, path_sep, -1); + if(sepIndex < 0) return path; path.size = sepIndex; @@ -11,16 +19,24 @@ str path_dirname(str path){ } str path_basename(str path, bool remove_ext){ - i32 nameIndex = str_seekCharReverse(path, path_sep, 0) + 1; - if(nameIndex == path.size) + if(path.size == 0) return path; - path.data += nameIndex; - path.size -= nameIndex; - if(remove_ext) + // remove trailing slash (name/) + if(path.data[path.size - 1] == path_sep){ + path.size -= 1; + } + + i32 nameIndex = str_seekCharReverse(path, path_sep, -1) + 1; + if((u32)nameIndex != 0){ + path.data += nameIndex; + path.size -= nameIndex; + } + + if(!remove_ext) return path; - i32 extIndex = str_seekCharReverse(path, '.', -1); + i32 extIndex = str_seekCharReverse(path, '.', -1); if(extIndex > 0){ path.size = extIndex; path.isZeroTerminated = false;