1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/filefn.h
3 // Purpose:     File- and directory-related functions
4 // Author:      Julian Smart
5 // Modified by:
6 // Created:     29/01/98
7 // Copyright:   (c) 1998 Julian Smart
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef   _FILEFN_H_
12 #define   _FILEFN_H_
13 
14 #include "wx/list.h"
15 #include "wx/arrstr.h"
16 
17 #ifdef __WXWINCE__
18     #include "wx/msw/wince/time.h"
19     #include "wx/msw/private.h"
20 #else
21     #include <time.h>
22 #endif
23 
24 #ifndef __WXWINCE__
25     #include <sys/types.h>
26     #include <sys/stat.h>
27 #endif
28 
29 #ifdef __OS2__
30 // need to check for __OS2__ first since currently both
31 // __OS2__ and __UNIX__ are defined.
32     #include <process.h>
33     #include "wx/os2/private.h"
34     #ifdef __WATCOMC__
35         #include <direct.h>
36     #endif
37     #include <io.h>
38     #ifdef __EMX__
39         #include <unistd.h>
40     #endif
41 #elif defined(__UNIX__)
42     #include <unistd.h>
43     #include <dirent.h>
44 #endif
45 
46 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
47 #if !defined( __GNUWIN32__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
48     #include <direct.h>
49     #include <dos.h>
50     #include <io.h>
51 #endif // __WINDOWS__
52 #endif // native Win compiler
53 
54 #if defined(__DOS__)
55     #ifdef __WATCOMC__
56         #include <direct.h>
57         #include <dos.h>
58         #include <io.h>
59     #endif
60     #ifdef __DJGPP__
61         #include <io.h>
62         #include <unistd.h>
63     #endif
64 #endif
65 
66 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
67                     // this (3.1 I believe) and how to test for it.
68                     // If this works for Borland 4.0 as well, then no worries.
69     #include <dir.h>
70 #endif
71 
72 #ifndef __WXWINCE__
73     #include  <fcntl.h>       // O_RDONLY &c
74 #endif
75 
76 // ----------------------------------------------------------------------------
77 // constants
78 // ----------------------------------------------------------------------------
79 
80 #if defined(__VISUALC__) || defined(__DIGITALMARS__)
81     typedef int mode_t;
82 #endif
83 
84 #ifdef __WXWINCE__
85     typedef long off_t;
86 #else
87     // define off_t
88     #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
89         #include  <sys/types.h>
90     #else
91         typedef long off_t;
92     #endif
93 #endif
94 
95 #if defined(__VISUALC__) && !defined(__WXWINCE__)
96     typedef _off_t off_t;
97 #elif defined(__SYMANTEC__)
98     typedef long off_t;
99 #endif
100 
101 enum wxSeekMode
102 {
103   wxFromStart,
104   wxFromCurrent,
105   wxFromEnd
106 };
107 
108 enum wxFileKind
109 {
110   wxFILE_KIND_UNKNOWN,
111   wxFILE_KIND_DISK,     // a file supporting seeking to arbitrary offsets
112   wxFILE_KIND_TERMINAL, // a tty
113   wxFILE_KIND_PIPE      // a pipe
114 };
115 
116 // we redefine these constants here because S_IREAD &c are _not_ standard
117 // however, we do assume that the values correspond to the Unix umask bits
118 enum wxPosixPermissions
119 {
120     // standard Posix names for these permission flags:
121     wxS_IRUSR = 00400,
122     wxS_IWUSR = 00200,
123     wxS_IXUSR = 00100,
124 
125     wxS_IRGRP = 00040,
126     wxS_IWGRP = 00020,
127     wxS_IXGRP = 00010,
128 
129     wxS_IROTH = 00004,
130     wxS_IWOTH = 00002,
131     wxS_IXOTH = 00001,
132 
133     // longer but more readable synonyms for the constants above:
134     wxPOSIX_USER_READ = wxS_IRUSR,
135     wxPOSIX_USER_WRITE = wxS_IWUSR,
136     wxPOSIX_USER_EXECUTE = wxS_IXUSR,
137 
138     wxPOSIX_GROUP_READ = wxS_IRGRP,
139     wxPOSIX_GROUP_WRITE = wxS_IWGRP,
140     wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
141 
142     wxPOSIX_OTHERS_READ = wxS_IROTH,
143     wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
144     wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
145 
146     // default mode for the new files: allow reading/writing them to everybody but
147     // the effective file mode will be set after anding this value with umask and
148     // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
149     wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
150                    wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
151                    wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
152 
153     // default mode for the new directories (see wxFileName::Mkdir): allow
154     // reading/writing/executing them to everybody, but just like wxS_DEFAULT
155     // the effective directory mode will be set after anding this value with umask
156     wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
157                        wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
158                        wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
159 };
160 
161 // ----------------------------------------------------------------------------
162 // declare our versions of low level file functions: some compilers prepend
163 // underscores to the usual names, some also have Unicode versions of them
164 // ----------------------------------------------------------------------------
165 
166 // Wrappers around Win32 api functions like CreateFile, ReadFile and such
167 // Implemented in filefnwce.cpp
168 #if defined( __WXWINCE__)
169     typedef __int64 wxFileOffset;
170     #define wxFileOffsetFmtSpec wxT("I64")
171     WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode));
172     WXDLLIMPEXP_BASE int wxCRT_Access(const wxChar *name, int WXUNUSED(how));
173     WXDLLIMPEXP_BASE int wxCRT_Chmod(const wxChar *name, int WXUNUSED(how));
174     WXDLLIMPEXP_BASE int wxClose(int fd);
175     WXDLLIMPEXP_BASE int wxFsync(int WXUNUSED(fd));
176     WXDLLIMPEXP_BASE int wxRead(int fd, void *buf, unsigned int count);
177     WXDLLIMPEXP_BASE int wxWrite(int fd, const void *buf, unsigned int count);
178     WXDLLIMPEXP_BASE int wxEof(int fd);
179     WXDLLIMPEXP_BASE wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
180     #define wxLSeek wxSeek
181     WXDLLIMPEXP_BASE wxFileOffset wxTell(int fd);
182 
183     // always Unicode under WinCE
184     #define   wxCRT_MkDir      _wmkdir
185     #define   wxCRT_RmDir      _wrmdir
186     #define   wxCRT_Stat       _wstat
187     #define   wxStructStat struct _stat
188 #elif (defined(__WINDOWS__) || defined(__OS2__)) && \
189       ( \
190         defined(__VISUALC__) || \
191         defined(__MINGW64_TOOLCHAIN__) || \
192         (defined(__MINGW32__) && !defined(__WINE__) && \
193                                 wxCHECK_W32API_VERSION(0, 5)) || \
194         defined(__DMC__) || \
195         defined(__WATCOMC__) || \
196         defined(__BORLANDC__) \
197       )
198 
199     // temporary defines just used immediately below
200     #undef wxHAS_HUGE_FILES
201     #undef wxHAS_HUGE_STDIO_FILES
202 
203     // detect compilers which have support for huge files
204     #if defined(__VISUALC__)
205         #define wxHAS_HUGE_FILES 1
206     #elif defined(__MINGW32__)
207         #define wxHAS_HUGE_FILES 1
208     #elif defined(_LARGE_FILES)
209         #define wxHAS_HUGE_FILES 1
210     #endif
211 
212     // detect compilers which have support for huge stdio files
213     #if wxCHECK_VISUALC_VERSION(8)
214         #define wxHAS_HUGE_STDIO_FILES
215         #define wxFseek _fseeki64
216         #define wxFtell _ftelli64
217     #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
218         #define wxHAS_HUGE_STDIO_FILES
219 
220         wxDECL_FOR_STRICT_MINGW32(int, fseeko64, (FILE*, long long, int))
221         #define wxFseek fseeko64
222 
223         #ifdef wxNEEDS_STRICT_ANSI_WORKAROUNDS
224             // Unfortunately ftello64() is not defined in the library for
225             // whatever reason but as an inline function, so define wxFtell()
226             // here similarly.
wxFtell(FILE * fp)227             inline long long wxFtell(FILE* fp)
228             {
229                 fpos_t pos;
230                 return fgetpos(fp, &pos) == 0 ? pos : -1LL;
231             }
232         #else
233             #define wxFtell ftello64
234         #endif
235     #endif
236 
237     // other Windows compilers (DMC, Watcom, and Borland) don't have huge file
238     // support (or at least not all functions needed for it by wx) currently
239 
240     // types
241 
242     #ifdef wxHAS_HUGE_FILES
243         typedef wxLongLong_t wxFileOffset;
244         #define wxFileOffsetFmtSpec wxLongLongFmtSpec
245     #else
246         typedef off_t wxFileOffset;
247     #endif
248 
249     // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
250     // resolution operator present in wxPOSIX_IDENT for it
251     #ifdef __BORLANDC__
252         #define wxPOSIX_STRUCT(s)    struct s
253     #else
254         #define wxPOSIX_STRUCT(s)    struct wxPOSIX_IDENT(s)
255     #endif
256 
257     // Notice that Watcom is the only compiler to have a wide char
258     // version of struct stat as well as a wide char stat function variant.
259     // This was dropped since OW 1.4 "for consistency across platforms".
260     //
261     // Borland is also special in that it uses _stat with Unicode functions
262     // (for MSVC compatibility?) but stat with ANSI ones
263     #ifdef __BORLANDC__
264         #if wxHAS_HUGE_FILES
265             #define wxStructStat struct stati64
266         #else
267             #if wxUSE_UNICODE
268                 #define wxStructStat struct _stat
269             #else
270                 #define wxStructStat struct stat
271             #endif
272         #endif
273     #else // !__BORLANDC__
274         #ifdef wxHAS_HUGE_FILES
275             #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
276                 #define wxStructStat struct _wstati64
277             #else
278                 #define wxStructStat struct _stati64
279             #endif
280         #else
281             #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
282                 #define wxStructStat struct _wstat
283             #else
284                 #define wxStructStat struct _stat
285             #endif
286         #endif
287     #endif // __BORLANDC__/!__BORLANDC__
288 
289 
290     // functions
291 
292     // MSVC and compatible compilers prepend underscores to the POSIX function
293     // names, other compilers don't and even if their later versions usually do
294     // define the versions with underscores for MSVC compatibility, it's better
295     // to avoid using them as they're not present in earlier versions and
296     // always using the native functions spelling is easier than testing for
297     // the versions
298     #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64_TOOLCHAIN__)
299         #define wxPOSIX_IDENT(func)    ::func
300     #else // by default assume MSVC-compatible names
301         #define wxPOSIX_IDENT(func)    _ ## func
302         #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
303     #endif
304 
305     // first functions not working with strings, i.e. without ANSI/Unicode
306     // complications
307     #define   wxClose      wxPOSIX_IDENT(close)
308 
309     #define wxRead         wxPOSIX_IDENT(read)
310     #define wxWrite        wxPOSIX_IDENT(write)
311 
312     #ifdef wxHAS_HUGE_FILES
313         #ifndef __MINGW64_TOOLCHAIN__
314             #define   wxSeek       wxPOSIX_IDENT(lseeki64)
315             #define   wxLseek      wxPOSIX_IDENT(lseeki64)
316             #define   wxTell       wxPOSIX_IDENT(telli64)
317         #else
318             // unfortunately, mingw-W64 is somewhat inconsistent...
319             #define   wxSeek       _lseeki64
320             #define   wxLseek      _lseeki64
321             #define   wxTell       _telli64
322         #endif
323     #else // !wxHAS_HUGE_FILES
324         #define   wxSeek       wxPOSIX_IDENT(lseek)
325         #define   wxLseek      wxPOSIX_IDENT(lseek)
326         #define   wxTell       wxPOSIX_IDENT(tell)
327     #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
328 
329     #ifndef __WATCOMC__
330          #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
331              // NB: this one is not POSIX and always has the underscore
332              #define   wxFsync      _commit
333 
334              // could be already defined by configure (Cygwin)
335              #ifndef HAVE_FSYNC
336                  #define HAVE_FSYNC
337              #endif
338         #endif // BORLANDC
339     #endif
340 
341     #define   wxEof        wxPOSIX_IDENT(eof)
342 
343     // then the functions taking strings
344 
345     // first the ANSI versions
346     #define   wxCRT_OpenA       wxPOSIX_IDENT(open)
347     #define   wxCRT_AccessA     wxPOSIX_IDENT(access)
348     #define   wxCRT_ChmodA      wxPOSIX_IDENT(chmod)
349     #define   wxCRT_MkDirA      wxPOSIX_IDENT(mkdir)
350     #define   wxCRT_RmDirA      wxPOSIX_IDENT(rmdir)
351     #ifdef wxHAS_HUGE_FILES
352         // MinGW-64 provides underscore-less versions of all file functions
353         // except for this one.
354         #ifdef __MINGW64_TOOLCHAIN__
355             #define   wxCRT_StatA       _stati64
356         #else
357             #define   wxCRT_StatA       wxPOSIX_IDENT(stati64)
358         #endif
359     #else
360         // Unfortunately Watcom is not consistent
361         #if defined(__OS2__) && defined(__WATCOMC__)
362             #define   wxCRT_StatA       _stat
363         #else
364             #define   wxCRT_StatA       wxPOSIX_IDENT(stat)
365         #endif
366     #endif
367 
368     // then wide char ones
369     #if wxUSE_UNICODE
370         // special workaround for buggy wopen() in bcc 5.5
371         #if defined(__BORLANDC__) && \
372             (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
373                 WXDLLIMPEXP_BASE int wxCRT_OpenW(const wxChar *pathname,
374                                                  int flags, mode_t mode);
375         #else
376             #define wxCRT_OpenW       _wopen
377         #endif
378 
379         #define   wxCRT_AccessW     _waccess
380         #define   wxCRT_ChmodW      _wchmod
381         #define   wxCRT_MkDirW      _wmkdir
382         #define   wxCRT_RmDirW      _wrmdir
383         #ifdef wxHAS_HUGE_FILES
384             #define   wxCRT_StatW       _wstati64
385         #else
386             #define   wxCRT_StatW       _wstat
387         #endif
388     #endif // wxUSE_UNICODE
389 
390 
391     // finally the default char-type versions
392     #if wxUSE_UNICODE
393         #if wxUSE_UNICODE_MSLU
394             // implement the missing file functions in Win9x ourselves
395             WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name,
396                                                int flags, int mode);
397             WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name,
398                                                  int mode);
399             WXDLLIMPEXP_BASE int wxMSLU__wchmod(const wxChar *name,
400                                                  int mode);
401             WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
402             WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
403 
404             WXDLLIMPEXP_BASE int
405             wxMSLU__wstat(const wxChar *name, wxStructStat *buffer);
406 
407             #define   wxCRT_Open       wxMSLU__wopen
408 
409             #define   wxCRT_Access     wxMSLU__waccess
410             #define   wxCRT_Chmod      wxMSLU__wchmod
411             #define   wxCRT_MkDir      wxMSLU__wmkdir
412             #define   wxCRT_RmDir      wxMSLU__wrmdir
413             #define   wxCRT_Stat       wxMSLU__wstat
414         #else // !wxUSE_UNICODE_MSLU
415             #define wxCRT_Open      wxCRT_OpenW
416             #define wxCRT_Access    wxCRT_AccessW
417             #define wxCRT_Chmod     wxCRT_ChmodW
418             #define wxCRT_MkDir     wxCRT_MkDirW
419             #define wxCRT_RmDir     wxCRT_RmDirW
420             #define wxCRT_Stat      wxCRT_StatW
421 
422             wxDECL_FOR_STRICT_MINGW32(int, _wmkdir, (const wchar_t*))
423             wxDECL_FOR_STRICT_MINGW32(int, _wrmdir, (const wchar_t*))
424         #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
425     #else // !wxUSE_UNICODE
426         #define wxCRT_Open      wxCRT_OpenA
427         #define wxCRT_Access    wxCRT_AccessA
428         #define wxCRT_Chmod     wxCRT_ChmodA
429         #define wxCRT_MkDir     wxCRT_MkDirA
430         #define wxCRT_RmDir     wxCRT_RmDirA
431         #define wxCRT_Stat      wxCRT_StatA
432     #endif // wxUSE_UNICODE/!wxUSE_UNICODE
433 
434 
435     // constants (unless already defined by the user code)
436     #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
437         #ifndef O_RDONLY
438             #define   O_RDONLY    _O_RDONLY
439             #define   O_WRONLY    _O_WRONLY
440             #define   O_RDWR      _O_RDWR
441             #define   O_EXCL      _O_EXCL
442             #define   O_CREAT     _O_CREAT
443             #define   O_BINARY    _O_BINARY
444         #endif
445 
446         #ifndef S_IFMT
447             #define   S_IFMT      _S_IFMT
448             #define   S_IFDIR     _S_IFDIR
449             #define   S_IFREG     _S_IFREG
450         #endif
451     #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
452 
453     #ifdef wxHAS_HUGE_FILES
454         // wxFile is present and supports large files.
455         #if wxUSE_FILE
456             #define wxHAS_LARGE_FILES
457         #endif
458         // wxFFile is present and supports large files
459         #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
460             #define wxHAS_LARGE_FFILES
461         #endif
462     #endif
463 
464     // private defines, undefine so that nobody gets tempted to use
465     #undef wxHAS_HUGE_FILES
466     #undef wxHAS_HUGE_STDIO_FILES
467 #else // Unix or Windows using unknown compiler, assume POSIX supported
468     typedef off_t wxFileOffset;
469     #ifdef HAVE_LARGEFILE_SUPPORT
470         #define wxFileOffsetFmtSpec wxLongLongFmtSpec
471         wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
472                                 BadFileSizeType );
473         // wxFile is present and supports large files
474         #if wxUSE_FILE
475             #define wxHAS_LARGE_FILES
476         #endif
477         // wxFFile is present and supports large files
478         #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
479             #define wxHAS_LARGE_FFILES
480         #endif
481         #ifdef HAVE_FSEEKO
482             #define wxFseek fseeko
483             #define wxFtell ftello
484         #endif
485     #else
486         #define wxFileOffsetFmtSpec wxT("")
487     #endif
488     // functions
489     #define   wxClose      close
490     #define   wxRead       ::read
491     #define   wxWrite      ::write
492     #define   wxLseek      lseek
493     #define   wxSeek       lseek
494     #define   wxFsync      fsync
495     #define   wxEof        eof
496     #define   wxCRT_MkDir      mkdir
497     #define   wxCRT_RmDir      rmdir
498 
499     #define   wxTell(fd)   lseek(fd, 0, SEEK_CUR)
500 
501     #define   wxStructStat struct stat
502 
503     #define   wxCRT_Open       open
504     #define   wxCRT_Stat       stat
505     #define   wxCRT_Lstat      lstat
506     #define   wxCRT_Access     access
507     #define   wxCRT_Chmod      chmod
508 
509     #define wxHAS_NATIVE_LSTAT
510 #endif // platforms
511 
512 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
513 // wxCRT_Stat to avoid #ifdefs in the code using it
514 #ifndef wxHAS_NATIVE_LSTAT
515     #define wxCRT_Lstat wxCRT_Stat
516 #endif
517 
518 // define wxFseek/wxFtell to large file versions if available (done above) or
519 // to fseek/ftell if not, to save ifdefs in using code
520 #ifndef wxFseek
521     #define wxFseek fseek
522 #endif
523 #ifndef wxFtell
524     #define wxFtell ftell
525 #endif
526 
wxAccess(const wxString & path,mode_t mode)527 inline int wxAccess(const wxString& path, mode_t mode)
528     { return wxCRT_Access(path.fn_str(), mode); }
wxChmod(const wxString & path,mode_t mode)529 inline int wxChmod(const wxString& path, mode_t mode)
530     { return wxCRT_Chmod(path.fn_str(), mode); }
wxOpen(const wxString & path,int flags,mode_t mode)531 inline int wxOpen(const wxString& path, int flags, mode_t mode)
532     { return wxCRT_Open(path.fn_str(), flags, mode); }
533 
534 // FIXME-CE: provide our own implementations of the missing CRT functions
535 #ifndef __WXWINCE__
wxStat(const wxString & path,wxStructStat * buf)536 inline int wxStat(const wxString& path, wxStructStat *buf)
537     { return wxCRT_Stat(path.fn_str(), buf); }
wxLstat(const wxString & path,wxStructStat * buf)538 inline int wxLstat(const wxString& path, wxStructStat *buf)
539     { return wxCRT_Lstat(path.fn_str(), buf); }
wxRmDir(const wxString & path)540 inline int wxRmDir(const wxString& path)
541     { return wxCRT_RmDir(path.fn_str()); }
542 #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
543         || (defined(__OS2__) && defined(__WATCOMC__))
544 inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
545     { return wxCRT_MkDir(path.fn_str()); }
546 #else
wxMkDir(const wxString & path,mode_t mode)547 inline int wxMkDir(const wxString& path, mode_t mode)
548     { return wxCRT_MkDir(path.fn_str(), mode); }
549 #endif
550 #endif // !__WXWINCE__
551 
552 #ifdef O_BINARY
553     #define wxO_BINARY O_BINARY
554 #else
555     #define wxO_BINARY 0
556 #endif
557 
558 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
559 //
560 // VisualAge C++ V4.0 cannot have any external linkage const decs
561 // in headers included by more than one primary source
562 //
563 extern const int wxInvalidOffset;
564 #else
565 const int wxInvalidOffset = -1;
566 #endif
567 
568 // ----------------------------------------------------------------------------
569 // functions
570 // ----------------------------------------------------------------------------
571 WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
572 
573 // does the path exist? (may have or not '/' or '\\' at the end)
574 WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
575 
576 WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
577 
578 // Get filename
579 WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
580 WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
581 
582 // Get directory
583 WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
584 
585 // all deprecated functions below are deprecated in favour of wxFileName's methods
586 #if WXWIN_COMPATIBILITY_2_8
587 
588 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
589 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
590 
591 wxDEPRECATED_BUT_USED_INTERNALLY(
592     WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
593 wxDEPRECATED_BUT_USED_INTERNALLY(
594     WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
595 
596 // Strip the extension, in situ
597 // Deprecated in favour of wxFileName::StripExtension() but notice that their
598 // behaviour is slightly different, see the manual
599 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
600 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
601 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
602 
603 // Get a temporary filename
604 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
605 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
606 
607 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
608 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
609 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
610     // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
611 
612 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
613 // and make (if under the home tree) relative to home
614 // [caller must copy-- volatile]
615 wxDEPRECATED(
616 WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
617                                    const wxString& envname = wxEmptyString,
618                                    const wxString& user = wxEmptyString) );
619     // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
620 
621 // Destructive removal of /./ and /../ stuff
622 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
623 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
624 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
625     // DEPRECATED: use wxFileName::Normalize instead
626 
627 // Allocate a copy of the full absolute path
628 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
629     // DEPRECATED: use wxFileName::MakeAbsolute instead
630 #endif
631 
632 // Get first file name matching given wild card.
633 // Flags are reserved for future use.
634 #define wxFILE  1
635 #define wxDIR   2
636 WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
637 WXDLLIMPEXP_BASE wxString wxFindNextFile();
638 
639 // Does the pattern contain wildcards?
640 WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
641 
642 // Does the pattern match the text (usually a filename)?
643 // If dot_special is true, doesn't match * against . (eliminating
644 // `hidden' dot files)
645 WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern,  const wxString& text, bool dot_special = true);
646 
647 // Concatenate two files to form third
648 WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
649 
650 // Copy file1 to file2
651 WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
652                                  bool overwrite = true);
653 
654 // Remove file
655 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
656 
657 // Rename file
658 WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
659 
660 // Get current working directory.
661 #if WXWIN_COMPATIBILITY_2_6
662 // If buf is NULL, allocates space using new, else
663 // copies into buf.
664 // IMPORTANT NOTE getcwd is know not to work under some releases
665 // of Win32s 1.3, according to MS release notes!
666 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = NULL, int sz = 1000) );
667 // new and preferred version of wxGetWorkingDirectory
668 // NB: can't have the same name because of overloading ambiguity
669 #endif // WXWIN_COMPATIBILITY_2_6
670 WXDLLIMPEXP_BASE wxString wxGetCwd();
671 
672 // Set working directory
673 WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
674 
675 // Make directory
676 WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
677 
678 // Remove directory. Flags reserved for future use.
679 WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
680 
681 // Return the type of an open file
682 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
683 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
684 
685 #if WXWIN_COMPATIBILITY_2_6
686 // compatibility defines, don't use in new code
687 wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
wxPathExists(const wxChar * pszPathName)688 inline bool wxPathExists(const wxChar *pszPathName)
689 {
690     return wxDirExists(pszPathName);
691 }
692 #endif //WXWIN_COMPATIBILITY_2_6
693 
694 // permissions; these functions work both on files and directories:
695 WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
696 WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
697 WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
698 
699 // ----------------------------------------------------------------------------
700 // separators in file names
701 // ----------------------------------------------------------------------------
702 
703 // between file name and extension
704 #define wxFILE_SEP_EXT        wxT('.')
705 
706 // between drive/volume name and the path
707 #define wxFILE_SEP_DSK        wxT(':')
708 
709 // between the path components
710 #define wxFILE_SEP_PATH_DOS   wxT('\\')
711 #define wxFILE_SEP_PATH_UNIX  wxT('/')
712 #define wxFILE_SEP_PATH_MAC   wxT(':')
713 #define wxFILE_SEP_PATH_VMS   wxT('.') // VMS also uses '[' and ']'
714 
715 // separator in the path list (as in PATH environment variable)
716 // there is no PATH variable in Classic Mac OS so just use the
717 // semicolon (it must be different from the file name separator)
718 // NB: these are strings and not characters on purpose!
719 #define wxPATH_SEP_DOS        wxT(";")
720 #define wxPATH_SEP_UNIX       wxT(":")
721 #define wxPATH_SEP_MAC        wxT(";")
722 
723 // platform independent versions
724 #if defined(__UNIX__) && !defined(__OS2__)
725   // CYGWIN also uses UNIX settings
726   #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_UNIX
727   #define wxPATH_SEP          wxPATH_SEP_UNIX
728 #elif defined(__MAC__)
729   #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_MAC
730   #define wxPATH_SEP          wxPATH_SEP_MAC
731 #else   // Windows and OS/2
732   #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_DOS
733   #define wxPATH_SEP          wxPATH_SEP_DOS
734 #endif  // Unix/Windows
735 
736 // this is useful for wxString::IsSameAs(): to compare two file names use
737 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
738 #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
739   #define wxARE_FILENAMES_CASE_SENSITIVE  true
740 #else   // Windows, Mac OS and OS/2
741   #define wxARE_FILENAMES_CASE_SENSITIVE  false
742 #endif  // Unix/Windows
743 
744 // is the char a path separator?
wxIsPathSeparator(wxChar c)745 inline bool wxIsPathSeparator(wxChar c)
746 {
747     // under DOS/Windows we should understand both Unix and DOS file separators
748 #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
749     return c == wxFILE_SEP_PATH;
750 #else
751     return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
752 #endif
753 }
754 
755 // does the string ends with path separator?
756 WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
757 
758 #if WXWIN_COMPATIBILITY_2_8
759 // split the full path into path (including drive for DOS), name and extension
760 // (understands both '/' and '\\')
761 // Deprecated in favour of wxFileName::SplitPath
762 wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
763                                                 wxString *pstrPath,
764                                                 wxString *pstrName,
765                                                 wxString *pstrExt) );
766 #endif
767 
768 // find a file in a list of directories, returns false if not found
769 WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
770 
771 // Get the OS directory if appropriate (such as the Windows directory).
772 // On non-Windows platform, probably just return the empty string.
773 WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
774 
775 #if wxUSE_DATETIME
776 
777 // Get file modification time
778 WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
779 
780 #endif // wxUSE_DATETIME
781 
782 // Parses the wildCard, returning the number of filters.
783 // Returns 0 if none or if there's a problem,
784 // The arrays will contain an equal number of items found before the error.
785 // wildCard is in the form:
786 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
787 WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
788 
789 // ----------------------------------------------------------------------------
790 // classes
791 // ----------------------------------------------------------------------------
792 
793 #ifdef __UNIX__
794 
795 // set umask to the given value in ctor and reset it to the old one in dtor
796 class WXDLLIMPEXP_BASE wxUmaskChanger
797 {
798 public:
799     // change the umask to the given one if it is not -1: this allows to write
800     // the same code whether you really want to change umask or not, as is in
801     // wxFileConfig::Flush() for example
wxUmaskChanger(int umaskNew)802     wxUmaskChanger(int umaskNew)
803     {
804         m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
805     }
806 
~wxUmaskChanger()807     ~wxUmaskChanger()
808     {
809         if ( m_umaskOld != -1 )
810             umask((mode_t)m_umaskOld);
811     }
812 
813 private:
814     int m_umaskOld;
815 };
816 
817 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
818 // nothing elsewhere
819 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
820 
821 #else // !__UNIX__
822 
823 #define wxCHANGE_UMASK(m)
824 
825 #endif // __UNIX__/!__UNIX__
826 
827 
828 // Path searching
829 class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
830 {
831 public:
wxPathList()832     wxPathList() {}
wxPathList(const wxArrayString & arr)833     wxPathList(const wxArrayString &arr)
834         { Add(arr); }
835 
836     // Adds all paths in environment variable
837     void AddEnvList(const wxString& envVariable);
838 
839     // Adds given path to this list
840     bool Add(const wxString& path);
841     void Add(const wxArrayString &paths);
842 
843     // Find the first full path for which the file exists
844     wxString FindValidPath(const wxString& filename) const;
845 
846     // Find the first full path for which the file exists; ensure it's an
847     // absolute path that gets returned.
848     wxString FindAbsoluteValidPath(const wxString& filename) const;
849 
850     // Given full path and filename, add path to list
851     bool EnsureFileAccessible(const wxString& path);
852 
853 #if WXWIN_COMPATIBILITY_2_6
854     // Returns true if the path is in the list
855     wxDEPRECATED( bool Member(const wxString& path) const );
856 #endif
857 };
858 
859 #endif // _WX_FILEFN_H_
860