diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index d536206ea15b4ee0faa7c46139855b6e396b5ef4..74b6a693094d587f2386c5241295f5cc9e5f1c8f 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -108,7 +108,26 @@ char* DLLCALL getfname(const char* path) } /****************************************************************************/ -/* Return a pointer to a file's extesion (beginning with '.') */ +/* Return the filename or last directory portion of a full pathname */ +/* A directory pathname is expected to end in a '/' */ +/****************************************************************************/ +char* DLLCALL getdirname(const char* path) +{ + char* last = lastchar(path); + if(*last == '/') { + if(last == path) + return last; + for(last--; last > path; last--) { + if(*last == '/' || *last == '\\') + return last + 1; + } + return last; + } + return getfname(path); +} + +/****************************************************************************/ +/* Return a pointer to a file's extension/suffix (beginning with '.') */ /****************************************************************************/ char* DLLCALL getfext(const char* path) { diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index 50c1199ff64b1c8ae4300e070b553a0de06b77ba..d33e940e31dc413da157df595ace35a6a8e717ad 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -228,6 +228,7 @@ DLLEXPORT char* DLLCALL getfname(const char* path); DLLEXPORT char* DLLCALL getfext(const char* path); DLLEXPORT int DLLCALL getfattr(const char* filename); DLLEXPORT ulong DLLCALL getfilecount(const char *inpath, const char* spec); +DLLEXPORT char* DLLCALL getdirname(const char* path); DLLEXPORT long DLLCALL getdirsize(const char* path, BOOL include_subdirs, BOOL subdir_only); DLLEXPORT ulong DLLCALL getdisksize(const char* path, ulong unit); DLLEXPORT ulong DLLCALL getfreediskspace(const char* path, ulong unit);