summaryrefslogtreecommitdiff
path: root/src/drivers/WinAPI
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2016-04-08 15:48:28 +0000
committerManolo Gouy <Manolo>2016-04-08 15:48:28 +0000
commit90682dbd481fca9b7b5b16086f3ac101081e8de5 (patch)
tree4157e2ca66d43f34431cf482e8c59d85ed3fcaa0 /src/drivers/WinAPI
parent62952ea2952768d922e2c93bcaa67e05c419f5a3 (diff)
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
Diffstat (limited to 'src/drivers/WinAPI')
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.H2
-rw-r--r--src/drivers/WinAPI/Fl_WinAPI_System_Driver.cxx34
2 files changed, 36 insertions, 0 deletions
diff --git a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
index cd7e03c50..8203317ac 100644
--- a/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
+++ b/src/drivers/WinAPI/Fl_WinAPI_System_Driver.H
@@ -72,6 +72,8 @@ public:
virtual int filename_expand(char *to,int tolen, const char *from);
virtual int filename_relative(char *to, int tolen, const char *from, const char *base);
virtual int filename_absolute(char *to, int tolen, const char *from);
+ virtual int filename_isdir(const char* n);
+ virtual int filename_isdir_quick(const char* n);
};
#endif // FL_WINAPI_SYSTEM_DRIVER_H
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 <FL/Fl.H>
#include <FL/fl_utf8.h>
+#include <FL/filename.H>
#include <stdio.h>
#include <stdarg.h>
#include <windows.h>
@@ -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$".
//