From d4ee41335ceeff73d3b8215310872614970477e4 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 17 May 2003 04:13:09 +0000 Subject: [PATCH] isdir() now supports file/path names that end in a slash on Win32. (truncates the slash before calling stat). --- src/xpdev/dirwrap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/xpdev/dirwrap.c b/src/xpdev/dirwrap.c index cc284591d1..bb8985ea76 100644 --- a/src/xpdev/dirwrap.c +++ b/src/xpdev/dirwrap.c @@ -497,17 +497,33 @@ BOOL DLLCALL fexistcase(char *path) #endif } +#if !defined(S_ISDIR) + #define S_ISDIR(x) ((x)&S_IFDIR) +#endif + /****************************************************************************/ /* Returns TRUE if the filename specified is a directory */ /****************************************************************************/ BOOL DLLCALL isdir(const char *filename) { + char path[MAX_PATH+1]; + char* p; struct stat st; - if(stat(filename, &st)!=0) + SAFECOPY(path,filename); + + p=lastchar(path); + if(p!=path && (*p=='/' || *p==BACKSLASH)) { /* chop off trailing slash */ +#if !defined(__unix__) + if(*(p-1)!=':') /* Don't change C:\ to C: */ +#endif + *p=0; + } + + if(stat(path, &st)!=0) return(FALSE); - return((st.st_mode&S_IFDIR) ? TRUE : FALSE); + return(S_ISDIR(st.st_mode) ? TRUE : FALSE); } /****************************************************************************/ -- GitLab