summaryrefslogtreecommitdiff
path: root/src/drivers/Posix
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/Posix')
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.H1
-rw-r--r--src/drivers/Posix/Fl_Posix_System_Driver.cxx40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.H b/src/drivers/Posix/Fl_Posix_System_Driver.H
index 67f060b04..20c1e40a2 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.H
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.H
@@ -86,6 +86,7 @@ public:
virtual int lock();
virtual void unlock();
virtual void* thread_message();
+ virtual int file_type(const char *filename);
};
#endif // FL_POSIX_SYSTEM_DRIVER_H
diff --git a/src/drivers/Posix/Fl_Posix_System_Driver.cxx b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
index a5b2d7269..0e5526c52 100644
--- a/src/drivers/Posix/Fl_Posix_System_Driver.cxx
+++ b/src/drivers/Posix/Fl_Posix_System_Driver.cxx
@@ -30,6 +30,7 @@
# include <dlfcn.h>
#endif
#include <sys/types.h>
+#include <sys/stat.h>
#include <pwd.h>
#include <unistd.h>
#include <time.h>
@@ -60,6 +61,17 @@ extern "C" {
}
#endif // __NetBSD__
+//
+// Define missing POSIX/XPG4 macros as needed...
+//
+#ifndef S_ISDIR
+# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
+# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
+# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
+# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
+#endif /* !S_ISDIR */
+
// Pointers you can use to change FLTK to another language.
// Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx
const char* fl_local_alt = "Alt";
@@ -521,6 +533,34 @@ void *Fl_Posix_System_Driver::dlopen(const char *filename)
return NULL;
}
+int Fl_Posix_System_Driver::file_type(const char *filename)
+{
+ int filetype;
+ struct stat fileinfo; // Information on file
+ if (!stat(filename, &fileinfo))
+ {
+ if (S_ISDIR(fileinfo.st_mode))
+ filetype = Fl_File_Icon::DIRECTORY;
+# ifdef S_ISFIFO
+ else if (S_ISFIFO(fileinfo.st_mode))
+ filetype = Fl_File_Icon::FIFO;
+# endif // S_ISFIFO
+# if defined(S_ISCHR) && defined(S_ISBLK)
+ else if (S_ISCHR(fileinfo.st_mode) || S_ISBLK(fileinfo.st_mode))
+ filetype = Fl_File_Icon::DEVICE;
+# endif // S_ISCHR && S_ISBLK
+# ifdef S_ISLNK
+ else if (S_ISLNK(fileinfo.st_mode))
+ filetype = Fl_File_Icon::LINK;
+# endif // S_ISLNK
+ else
+ filetype = Fl_File_Icon::PLAIN;
+ }
+ else
+ filetype = Fl_File_Icon::PLAIN;
+ return filetype;
+}
+
//
// End of "$Id$".
//