Commit bb721a40 authored by rswindell's avatar rswindell
Browse files

Added getdirname(): returns the filename or lastdirectory portion of a full

pathname (directories must end in a '/'). Unlike getfname() which returns an
empty string if passed a path ending in a '/'.
Useful with glob(.., GLOB_MARK).
parent c683fd1d
......@@ -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)
{
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment