summaryrefslogtreecommitdiff
path: root/src/Fl_File_Browser.cxx
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2005-08-18 14:08:17 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2005-08-18 14:08:17 +0000
commitc1ba87140e22e9e7b46fe90c0f98e38b7c8a94ca (patch)
tree19081ab89fb59d334623c584c872e99ddb4be57c /src/Fl_File_Browser.cxx
parenteca40efb6e42b352ca77d1d290b4149037b70efd (diff)
Fix new trailing slash usage, and restore correct OSX filesystem listing
(added filter to hide /dev and /.vol) src/Fl_File_Browser.cxx: - Fl_File_Browser::load(): use getfsstat() API on OSX, and don't bother adding a trailing slash to directories since we already have them! src/filename_list.cxx: - fl_filename_list(): Add 3 bytes (two possible slashes + nul byte) to temporary buffer, and document why we are using memcpy() instead of strcpy(). src/filename_isdir.cxx: - fl_filename_isdir(): Add check for trailing directory separator before wasting time doing a stat() call. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4526 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_File_Browser.cxx')
-rw-r--r--src/Fl_File_Browser.cxx42
1 files changed, 27 insertions, 15 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);