1 | // "$Id: filename.h 4350 2005-05-13 21:56:07Z dejan $" |
---|
2 | |
---|
3 | /* Copyright 1998-2005 by Bill Spitzak and others. |
---|
4 | * |
---|
5 | * Permission to use, copy, modify, and distribute this software for any |
---|
6 | * purpose with or without fee is hereby granted, provided that the above |
---|
7 | * copyright notice and this permission notice appear in all copies. |
---|
8 | * |
---|
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
---|
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
---|
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
---|
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
---|
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
---|
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
---|
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
---|
16 | * |
---|
17 | * Please report all bugs and problems to "fltk-bugs@fltk.org". |
---|
18 | * |
---|
19 | * These functions are not in the fltk namespace because they really |
---|
20 | * should not be part of fltk. They are used by the file chooser. |
---|
21 | */ |
---|
22 | |
---|
23 | #ifndef fltk_filename_h |
---|
24 | #define fltk_filename_h |
---|
25 | |
---|
26 | #include "FL_API.h" |
---|
27 | |
---|
28 | /*! \addtogroup utilities |
---|
29 | \{ */ |
---|
30 | |
---|
31 | FL_API const char* filename_normalize(char* output, int length, const char* input, const char* directory=0); |
---|
32 | inline char* filename_normalize(char* o, int l, char* i, const char* d=0) {return (char*)(filename_normalize(o,l,(const char*)i,d));} |
---|
33 | FL_API const char *filename_name(const char *); |
---|
34 | inline char* filename_name(char* a) {return (char*)(filename_name((const char*)a));} |
---|
35 | FL_API const char *filename_ext(const char *); |
---|
36 | inline char* filename_ext(char* a) {return (char*)(filename_ext((const char*)a));} |
---|
37 | FL_API bool filename_match(const char *, const char *pattern); // glob match |
---|
38 | FL_API bool filename_isdir(const char*); |
---|
39 | FL_API double filename_size(const char *); // return size of file |
---|
40 | FL_API long int filename_mtime(const char *); // return modification time |
---|
41 | |
---|
42 | /*! \} */ |
---|
43 | |
---|
44 | //////////////////////////////////////////////////////////////// |
---|
45 | // dirent (what a pain)... |
---|
46 | |
---|
47 | #if defined(__WATCOMC__) |
---|
48 | |
---|
49 | # include <sys/types.h> |
---|
50 | # include "direct.h" |
---|
51 | |
---|
52 | #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__MINGW32__) |
---|
53 | // Dummy version used on win32 that just holds a name: |
---|
54 | |
---|
55 | struct dirent {char d_name[1];}; |
---|
56 | |
---|
57 | #elif defined(__linux) |
---|
58 | // Newest Linux libc is broken when it emulates the 32-bit dirent, it |
---|
59 | // generates errors when the data like the inode number does not fit, even |
---|
60 | // though we are not going to look at anything other than the name. This |
---|
61 | // code seems to force the 64-bit version to be used: |
---|
62 | |
---|
63 | # ifndef _GNU_SOURCE |
---|
64 | # define _GNU_SOURCE |
---|
65 | # endif |
---|
66 | # include <features.h> |
---|
67 | # include <sys/types.h> |
---|
68 | # include <dirent.h> |
---|
69 | # define dirent dirent64 |
---|
70 | # define scandir scandir64 |
---|
71 | |
---|
72 | #else |
---|
73 | // warning: on some systems (very few nowadays?) <dirent.h> may not exist. |
---|
74 | // The correct information is in one of these three files: |
---|
75 | // #include <sys/ndir.h> |
---|
76 | // #include <sys/dir.h> |
---|
77 | // #include <ndir.h> |
---|
78 | // plus you must do the following #define: |
---|
79 | // #define dirent direct |
---|
80 | // I recommend you create a /usr/include/dirent.h containing the correct info |
---|
81 | |
---|
82 | # include <sys/types.h> |
---|
83 | # include <dirent.h> |
---|
84 | |
---|
85 | #endif |
---|
86 | |
---|
87 | /*! \addtogroup utilities */ |
---|
88 | FL_API int filename_list(const char *d, struct dirent ***); |
---|
89 | |
---|
90 | #ifndef PATH_MAX |
---|
91 | # ifdef _MAX_PATH |
---|
92 | # define PATH_MAX _MAX_PATH |
---|
93 | # else |
---|
94 | # define PATH_MAX 1024 |
---|
95 | # endif |
---|
96 | #endif |
---|
97 | |
---|
98 | #endif |
---|
99 | |
---|
100 | // End of "$Id: filename.h 4350 2005-05-13 21:56:07Z dejan $". |
---|