30 lines
692 B
C
30 lines
692 B
C
#include "tlibc/filesystem.h"
|
|
|
|
str path_dirname(str path){
|
|
i32 sepIndex = str_seekCharReverse(path, path_sep, 0);
|
|
if(sepIndex <= 0)
|
|
return path;
|
|
|
|
path.size = sepIndex;
|
|
path.isZeroTerminated = false;
|
|
return path;
|
|
}
|
|
|
|
str path_basename(str path, bool remove_ext){
|
|
i32 nameIndex = str_seekCharReverse(path, path_sep, 0) + 1;
|
|
if(nameIndex == path.size)
|
|
return path;
|
|
|
|
path.data += nameIndex;
|
|
path.size -= nameIndex;
|
|
if(remove_ext)
|
|
return path;
|
|
|
|
i32 extIndex = str_seekCharReverse(path, '.', -1);
|
|
if(extIndex > 0){
|
|
path.size = extIndex;
|
|
path.isZeroTerminated = false;
|
|
}
|
|
return path;
|
|
}
|