diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_File_Browser.cxx | 42 | ||||
| -rw-r--r-- | src/filename_isdir.cxx | 3 | ||||
| -rw-r--r-- | src/filename_list.cxx | 4 |
3 files changed, 33 insertions, 16 deletions
diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx index 22ae7eada..7698a8083 100644 --- a/src/Fl_File_Browser.cxx +++ b/src/Fl_File_Browser.cxx @@ -67,7 +67,6 @@ // CodeWarrior (__MWERKS__) gets its include paths confused, so we // temporarily disable this... #if defined(__APPLE__) && !defined(__MWERKS__) -# include <Carbon/Carbon.h> # include <sys/param.h> # include <sys/ucred.h> # include <sys/mount.h> @@ -496,20 +495,34 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load num_files ++; } #elif defined(__APPLE__) && !defined(__MWERKS__) - // All mounted volumes are in a directory called '/Volumes/' - // This seems to be the case on international installations, too. + // MacOS X and Darwin use getfsstat() system call... + int numfs; // Number of file systems + struct statfs *fs; // Buffer for file system info + + + // We always have the root filesystem. add("/", icon); - dirent **dir; - int n = fl_filename_list("/Volumes/", &dir, 0); - if (n>=0) { - int i; - for (i=0; i<n; i++) { - if (dir[i]->d_name[0]=='.') continue; - sprintf(filename, "/Volumes/%s", dir[i]->d_name); - add(filename, icon); - free(dir[i]); + + // Get the mounted filesystems... + numfs = getfsstat(NULL, 0, MNT_NOWAIT); + if (numfs > 0) { + // We have file systems, get them... + fs = new struct statfs[numfs]; + getfsstat(fs, sizeof(struct statfs) * numfs, MNT_NOWAIT); + + // Add filesystems to the list... + for (i = 0; i < numfs; i ++) { + // Ignore "/", "/dev", and "/.vol"... + if (fs[i].f_mntonname[1] && strcmp(fs[i].f_mntonname, "/dev") && + strcmp(fs[i].f_mntonname, "/.vol")) { + snprintf(filename, sizeof(filename), "%s/", fs[i].f_mntonname); + add(filename, icon); + } + num_files ++; } - free(dir); + + // Free the memory used for the file system info array... + delete[] fs; } #else // @@ -578,8 +591,7 @@ Fl_File_Browser::load(const char *directory,// I - Directory to load return (0); for (i = 0, num_dirs = 0; i < num_files; i ++) { - if (strcmp(files[i]->d_name, ".") && - strcmp(files[i]->d_name, "./")) { + if (strcmp(files[i]->d_name, "./")) { snprintf(filename, sizeof(filename), "%s/%s", directory_, files[i]->d_name); diff --git a/src/filename_isdir.cxx b/src/filename_isdir.cxx index e368fce1d..f1a3d2909 100644 --- a/src/filename_isdir.cxx +++ b/src/filename_isdir.cxx @@ -43,6 +43,9 @@ static inline int isdirsep(char c) {return c=='/' || c=='\\';} int fl_filename_isdir(const char* n) { struct stat s; + // Do a quick optimization for filenames with a trailing slash... + if (*n && isdirsep(n[strlen(n) - 1])) return 1; + #ifdef WIN32 char fn[1024]; int length; diff --git a/src/filename_list.cxx b/src/filename_list.cxx index 71335757b..b2b3858c7 100644 --- a/src/filename_list.cxx +++ b/src/filename_list.cxx @@ -79,7 +79,8 @@ int fl_filename_list(const char *d, dirent ***list, #else // append a '/' to all filenames that are directories int i, dirlen = strlen(d); - char *fullname = (char*)malloc(dirlen+FL_PATH_MAX+2); + char *fullname = (char*)malloc(dirlen+FL_PATH_MAX+3); // Add enough extra for two /'s and a nul + // Use memcpy for speed since we already know the length of the string... memcpy(fullname, d, dirlen+1); char *name = fullname + dirlen; if (name!=fullname && name[-1]!='/') *name++ = '/'; @@ -87,6 +88,7 @@ int fl_filename_list(const char *d, dirent ***list, dirent *de = (*list)[i]; int len = strlen(de->d_name); if (de->d_name[len-1]=='/' || len>FL_PATH_MAX) continue; + // Use memcpy for speed since we already know the length of the string... memcpy(name, de->d_name, len+1); if (fl_filename_isdir(fullname)) { if (len<FL_PATH_MAX) { |
