diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2005-08-17 21:56:22 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2005-08-17 21:56:22 +0000 |
| commit | eca40efb6e42b352ca77d1d290b4149037b70efd (patch) | |
| tree | 605f7653442f1a0ae8cd95af7e345708419d309a /src/filename_list.cxx | |
| parent | 760bca71abe9e35e393c05404672d362b463128e (diff) | |
This change is controversial. It changes the behavior of fl_filename_list
slightly by adding a forward slash after every directory name on every
supported OS. Included in this patch is a change in the code that
lists mounted volumes on OS X Mac.
Apple users, please check. Open FLUID, open the file dialog and
clear the current path. You shoudl see a list of mounted volumes.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4525 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/filename_list.cxx')
| -rw-r--r-- | src/filename_list.cxx | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/filename_list.cxx b/src/filename_list.cxx index e8fc37c9a..71335757b 100644 --- a/src/filename_list.cxx +++ b/src/filename_list.cxx @@ -29,6 +29,7 @@ #include <FL/filename.H> #include "flstring.h" +#include <stdlib.h> extern "C" { @@ -52,26 +53,52 @@ int fl_casealphasort(struct dirent **a, struct dirent **b) { int fl_filename_list(const char *d, dirent ***list, Fl_File_Sort_F *sort) { #ifndef HAVE_SCANDIR - return scandir(d, list, 0, sort); + int n = scandir(d, list, 0, sort); #elif defined(__hpux) || defined(__CYGWIN__) // HP-UX, Cygwin define the comparison function like this: - return scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort); + int n = scandir(d, list, 0, (int(*)(const dirent **, const dirent **))sort); #elif defined(__osf__) // OSF, DU 4.0x - return scandir(d, list, 0, (int(*)(dirent **, dirent **))sort); + int n = scandir(d, list, 0, (int(*)(dirent **, dirent **))sort); #elif defined(_AIX) // AIX is almost standard... - return scandir(d, list, 0, (int(*)(void*, void*))sort); + int n = scandir(d, list, 0, (int(*)(void*, void*))sort); #elif !defined(__sgi) // The vast majority of UNIX systems want the sort function to have this // prototype, most likely so that it can be passed to qsort without any // changes: - return scandir(d, list, 0, (int(*)(const void*,const void*))sort); + int n = scandir(d, list, 0, (int(*)(const void*,const void*))sort); #else // This version is when we define our own scandir (WIN32 and perhaps // some Unix systems) and apparently on IRIX: - return scandir(d, list, 0, sort); + int n = scandir(d, list, 0, sort); #endif + +#if defined(WIN32) && !defined(__CYGWIN__) + // we did this already during fl_scandir/win32 +#else + // append a '/' to all filenames that are directories + int i, dirlen = strlen(d); + char *fullname = (char*)malloc(dirlen+FL_PATH_MAX+2); + memcpy(fullname, d, dirlen+1); + char *name = fullname + dirlen; + if (name!=fullname && name[-1]!='/') *name++ = '/'; + for (i=0; i<n; i++) { + dirent *de = (*list)[i]; + int len = strlen(de->d_name); + if (de->d_name[len-1]=='/' || len>FL_PATH_MAX) continue; + memcpy(name, de->d_name, len+1); + if (fl_filename_isdir(fullname)) { + if (len<FL_PATH_MAX) { + char *dst = de->d_name + len; + *dst++ = '/'; + *dst = 0; + } + } + } + free(fullname); +#endif + return n; } // |
