From bd1e74b826ffa9d534747daf59421729bf223410 Mon Sep 17 00:00:00 2001 From: "Rob Swindell (on Debian Linux)" <rob@synchro.net> Date: Mon, 29 Apr 2024 21:06:50 -0700 Subject: [PATCH] Add getdircase() - like fexistcase(), but for sub-directory names --- src/xpdev/dirwrap.c | 18 ++++++++++++++---- src/xpdev/dirwrap.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index fd101e0e12..1384f3f5b8 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -577,9 +577,9 @@ bool fexist(const char *filespec) } /****************************************************************************/ -/* Fixes upper/lowercase filename for Unix file systems */ +/* Fixes upper/lowercase filename or dirname for Unix file systems */ /****************************************************************************/ -bool fexistcase(char *path) +static bool getfilecase(char *path, bool dir) { #if defined(_WIN32) @@ -595,7 +595,7 @@ bool fexistcase(char *path) _findclose(handle); - if(f.attrib&_A_SUBDIR) + if(INT_TO_BOOL(f.attrib&_A_SUBDIR) != dir) return(false); fname=getfname(path); /* Find filename in path */ @@ -636,7 +636,7 @@ bool fexistcase(char *path) } #endif - if(glob(globme,GLOB_MARK,NULL,&glb) != 0) + if(glob(globme, dir ? GLOB_ONLYDIR : GLOB_MARK, NULL, &glb) != 0) return(false); if(glb.gl_pathc>0) { @@ -657,6 +657,16 @@ bool fexistcase(char *path) #endif } +bool fexistcase(char *path) +{ + return getfilecase(path, false); +} + +bool getdircase(char* path) +{ + return getfilecase(path, true); +} + /****************************************************************************/ /* Returns true if the filename specified is a directory */ /****************************************************************************/ diff --git a/src/xpdev/dirwrap.h b/src/xpdev/dirwrap.h index c84c9b9e75..d9f4f7a33d 100644 --- a/src/xpdev/dirwrap.h +++ b/src/xpdev/dirwrap.h @@ -219,6 +219,7 @@ DLLEXPORT char* getfext(const char* path); DLLEXPORT int getfattr(const char* filename); DLLEXPORT int getfmode(const char* filename); DLLEXPORT uint getfilecount(const char *path); +DLLEXPORT bool getdircase(char* path); DLLEXPORT char* getdirname(const char* path); DLLEXPORT size_t getdirsize(const char* path, bool include_subdirs, bool subdir_only); DLLEXPORT uint64_t getdisksize(const char* path, uint64_t unit); -- GitLab