From 3a0fe7916436b5ce5f4ba252f4078dd649b67c6b Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 3 Dec 2001 18:29:49 +0000 Subject: Bug fixes and doco updates care of Sebastian. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1799 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/filename_isdir.cxx | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/filename_isdir.cxx') diff --git a/src/filename_isdir.cxx b/src/filename_isdir.cxx index 1d4d4cb05..4620e29e6 100644 --- a/src/filename_isdir.cxx +++ b/src/filename_isdir.cxx @@ -1,5 +1,5 @@ // -// "$Id: filename_isdir.cxx,v 1.4.2.5 2001/01/22 15:13:40 easysw Exp $" +// "$Id: filename_isdir.cxx,v 1.4.2.5.2.1 2001/12/03 18:29:49 easysw Exp $" // // Directory detection routines for the Fast Light Tool Kit (FLTK). // @@ -25,28 +25,39 @@ // Used by fl_file_chooser -#include -#include +#include "flstring.h" #include -#include +#include +#include + int filename_isdir(const char* n) { struct stat s; + #ifdef WIN32 char fn[1024]; int length; // This workaround brought to you by the fine folks at Microsoft! // (read lots of sarcasm in that...) - strncpy(fn, n, sizeof(fn) - 1); - fn[sizeof(fn) - 1] = '\0'; - length = strlen(fn); - if (length > 0 && (fn[length - 1] == '/' || fn[length - 1] == '\\')) - fn[length - 1] = '\0'; // Strip trailing slash... - n = fn; + length = strlen(n); + if (length < (int)(sizeof(fn) - 1)) { + if (length < 4 && isletter(n[0]) && n[1] == ':') { + // Always use D:/ for drive letters + fn[0] = n[0]; + strcpy(fn + 1, ":/"); + n = fn; + } else if (length > 0 && (n[length - 1] == '/' || n[length - 1] == '\\')) { + // Strip trailing slash from name... + strncpy(fn, n, sizeof(fn) - 1); + fn[length - 1] = '\0'; + n = fn; + } + } #endif + return !stat(n, &s) && (s.st_mode&0170000)==0040000; } // -// End of "$Id: filename_isdir.cxx,v 1.4.2.5 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: filename_isdir.cxx,v 1.4.2.5.2.1 2001/12/03 18:29:49 easysw Exp $". // -- cgit v1.2.3