|
fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation) ![]() |
00001 // 00002 // "$Id: filename_isdir.cxx 8063 2010-12-19 21:20:10Z matt $" 00003 // 00004 // Directory detection routines for the Fast Light Tool Kit (FLTK). 00005 // 00006 // Copyright 1998-2010 by Bill Spitzak and others. 00007 // 00008 // This library is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU Library General Public 00010 // License as published by the Free Software Foundation; either 00011 // version 2 of the License, or (at your option) any later version. 00012 // 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 // Library General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU Library General Public 00019 // License along with this library; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00021 // USA. 00022 // 00023 // Please report all bugs and problems on the following page: 00024 // 00025 // http://www.fltk.org/str.php 00026 // 00027 00028 // Used by fl_file_chooser 00029 00030 #include "flstring.h" 00031 #include <sys/types.h> 00032 #include <sys/stat.h> 00033 #include <ctype.h> 00034 #include <FL/filename.H> 00035 #include <FL/fl_utf8.h> 00036 00037 00038 #if defined(WIN32) || defined(__EMX__) && !defined(__CYGWIN__) 00039 static inline int isdirsep(char c) {return c=='/' || c=='\\';} 00040 #else 00041 #define isdirsep(c) ((c)=='/') 00042 #endif 00043 00044 int _fl_filename_isdir_quick(const char* n) { 00045 // Do a quick optimization for filenames with a trailing slash... 00046 if (*n && isdirsep(n[strlen(n) - 1])) return 1; 00047 return fl_filename_isdir(n); 00048 } 00049 00061 int fl_filename_isdir(const char* n) { 00062 struct stat s; 00063 char fn[FL_PATH_MAX]; 00064 int length; 00065 00066 length = strlen(n); 00067 00068 #ifdef WIN32 00069 // This workaround brought to you by the fine folks at Microsoft! 00070 // (read lots of sarcasm in that...) 00071 if (length < (int)(sizeof(fn) - 1)) { 00072 if (length < 4 && isalpha(n[0]) && n[1] == ':' && 00073 (isdirsep(n[2]) || !n[2])) { 00074 // Always use D:/ for drive letters 00075 fn[0] = n[0]; 00076 strcpy(fn + 1, ":/"); 00077 n = fn; 00078 } else if (length > 0 && isdirsep(n[length - 1])) { 00079 // Strip trailing slash from name... 00080 length --; 00081 memcpy(fn, n, length); 00082 fn[length] = '\0'; 00083 n = fn; 00084 } 00085 } 00086 #else 00087 // Matt: Just in case, we strip the slash for other operating 00088 // systems as well, avoid bugs by sloppy implementations 00089 // of "stat". 00090 if (length > 1 && isdirsep(n[length - 1])) { 00091 length --; 00092 memcpy(fn, n, length); 00093 fn[length] = '\0'; 00094 n = fn; 00095 } 00096 #endif 00097 00098 return !fl_stat(n, &s) && (s.st_mode&0170000)==0040000; 00099 } 00100 00101 // 00102 // End of "$Id: filename_isdir.cxx 8063 2010-12-19 21:20:10Z matt $". 00103 //