From 90682dbd481fca9b7b5b16086f3ac101081e8de5 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 8 Apr 2016 15:48:28 +0000 Subject: Rewrite filename_isdir.cxx for the driver model. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11555 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx') diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx index 6d32b4f6b..693fd296d 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx @@ -21,6 +21,7 @@ #include "Fl_WinAPI_System_Driver.H" #include #include +#include #include #include #include @@ -614,6 +615,39 @@ int Fl_WinAPI_System_Driver::filename_absolute(char *to, int tolen, const char * return 1; } +int Fl_WinAPI_System_Driver::filename_isdir(const char* n) +{ + struct stat s; + char fn[FL_PATH_MAX]; + int length; + length = (int) strlen(n); + // This workaround brought to you by the fine folks at Microsoft! + // (read lots of sarcasm in that...) + if (length < (int)(sizeof(fn) - 1)) { + if (length < 4 && isalpha(n[0]) && n[1] == ':' && + (isdirsep(n[2]) || !n[2])) { + // Always use D:/ for drive letters + fn[0] = n[0]; + strcpy(fn + 1, ":/"); + n = fn; + } else if (length > 0 && isdirsep(n[length - 1])) { + // Strip trailing slash from name... + length --; + memcpy(fn, n, length); + fn[length] = '\0'; + n = fn; + } + } + return !stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR; +} + +int Fl_WinAPI_System_Driver::filename_isdir_quick(const char* n) +{ + // Do a quick optimization for filenames with a trailing slash... + if (*n && isdirsep(n[strlen(n) - 1])) return 1; + return filename_isdir(n); +} + // // End of "$Id$". // -- cgit v1.2.3