summaryrefslogtreecommitdiff
path: root/src/filename_isdir.cxx
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/filename_isdir.cxx
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/filename_isdir.cxx')
-rw-r--r--src/filename_isdir.cxx56
1 files changed, 18 insertions, 38 deletions
diff --git a/src/filename_isdir.cxx b/src/filename_isdir.cxx
index 4e69445c1..378f17e4e 100644
--- a/src/filename_isdir.cxx
+++ b/src/filename_isdir.cxx
@@ -19,22 +19,21 @@
// Used by fl_file_chooser
#include "flstring.h"
-#include <sys/types.h>
-#include <FL/Fl_System_Driver.H> // for struct stat
-#include <ctype.h>
+#include <FL/Fl_System_Driver.H>
#include <FL/filename.H>
-#include <FL/fl_utf8.h>
+#include <FL/Fl.H>
-#if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__)
-static inline int isdirsep(char c) {return c=='/' || c=='\\';}
-#else
-#define isdirsep(c) ((c)=='/')
-#endif
-
-int _fl_filename_isdir_quick(const char* n) {
+/*
+ * filename_isdir_quick() is a private function that checks for a
+ * trailing slash and assumes that the passed name is a directory if
+ * it finds one. This function is used by Fl_File_Browser and
+ * Fl_File_Chooser to avoid extra stat() calls, but is not supported
+ * outside of FLTK...
+ */
+int Fl_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 fl_filename_isdir(n);
+ if (*n && n[strlen(n) - 1] == '/') return 1;
+ return filename_isdir(n);
}
/**
@@ -49,43 +48,24 @@ int _fl_filename_isdir_quick(const char* n) {
\return non zero if file exists and is a directory, zero otherwise
*/
int fl_filename_isdir(const char* n) {
+ return Fl::system_driver()->filename_isdir(n);
+}
+
+int Fl_System_Driver::filename_isdir(const char* n) {
struct stat s;
char fn[FL_PATH_MAX];
int length;
-
length = (int) strlen(n);
-
-#ifdef WIN32
- // 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;
- }
- }
-#else
// Matt: Just in case, we strip the slash for other operating
// systems as well, avoid bugs by sloppy implementations
// of "stat".
- if (length > 1 && isdirsep(n[length - 1])) {
+ if (length > 1 && n[length - 1] == '/') {
length --;
memcpy(fn, n, length);
fn[length] = '\0';
n = fn;
}
-#endif
-
- return !fl_stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR;
+ return !stat(n, &s) && (s.st_mode & S_IFMT) == S_IFDIR;
}
//