Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / filefn.h
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 wxClose(int fd);
174 WXDLLIMPEXP_BASE int wxFsync(int WXUNUSED(fd));
175 WXDLLIMPEXP_BASE int wxRead(int fd, void *buf, unsigned int count);
176 WXDLLIMPEXP_BASE int wxWrite(int fd, const void *buf, unsigned int count);
177 WXDLLIMPEXP_BASE int wxEof(int fd);
178 WXDLLIMPEXP_BASE wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
179 #define wxLSeek wxSeek
180 WXDLLIMPEXP_BASE wxFileOffset wxTell(int fd);
181
182 // always Unicode under WinCE
183 #define wxCRT_MkDir _wmkdir
184 #define wxCRT_RmDir _wrmdir
185 #define wxCRT_Stat _wstat
186 #define wxStructStat struct _stat
187 #elif (defined(__WINDOWS__) || defined(__OS2__)) && \
188 ( \
189 defined(__VISUALC__) || \
190 defined(__MINGW64__) || \
191 (defined(__MINGW32__) && !defined(__WINE__) && \
192 wxCHECK_W32API_VERSION(0, 5)) || \
193 defined(__DMC__) || \
194 defined(__WATCOMC__) || \
195 defined(__BORLANDC__) \
196 )
197
198 // temporary defines just used immediately below
199 #undef wxHAS_HUGE_FILES
200 #undef wxHAS_HUGE_STDIO_FILES
201
202 // detect compilers which have support for huge files
203 #if defined(__VISUALC__)
204 #define wxHAS_HUGE_FILES 1
205 #elif defined(__MINGW32__) || defined(__MINGW64__)
206 #define wxHAS_HUGE_FILES 1
207 #elif defined(_LARGE_FILES)
208 #define wxHAS_HUGE_FILES 1
209 #endif
210
211 // detect compilers which have support for huge stdio files
212 #if wxCHECK_VISUALC_VERSION(8)
213 #define wxHAS_HUGE_STDIO_FILES
214 #define wxFseek _fseeki64
215 #define wxFtell _ftelli64
216 #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
217 #define wxHAS_HUGE_STDIO_FILES
218 #define wxFseek fseeko64
219 #define wxFtell ftello64
220 #endif
221
222 // other Windows compilers (DMC, Watcom, and Borland) don't have huge file
223 // support (or at least not all functions needed for it by wx) currently
224
225 // types
226
227 #ifdef wxHAS_HUGE_FILES
228 typedef wxLongLong_t wxFileOffset;
229 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
230 #else
231 typedef off_t wxFileOffset;
232 #endif
233
234 // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
235 // resolution operator present in wxPOSIX_IDENT for it
236 #ifdef __BORLANDC__
237 #define wxPOSIX_STRUCT(s) struct s
238 #else
239 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
240 #endif
241
242 // Notice that Watcom is the only compiler to have a wide char
243 // version of struct stat as well as a wide char stat function variant.
244 // This was dropped since OW 1.4 "for consistency across platforms".
245 //
246 // Borland is also special in that it uses _stat with Unicode functions
247 // (for MSVC compatibility?) but stat with ANSI ones
248 #ifdef __BORLANDC__
249 #if wxHAS_HUGE_FILES
250 #define wxStructStat struct stati64
251 #else
252 #if wxUSE_UNICODE
253 #define wxStructStat struct _stat
254 #else
255 #define wxStructStat struct stat
256 #endif
257 #endif
258 #else // !__BORLANDC__
259 #ifdef wxHAS_HUGE_FILES
260 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
261 #define wxStructStat struct _wstati64
262 #else
263 #define wxStructStat struct _stati64
264 #endif
265 #else
266 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
267 #define wxStructStat struct _wstat
268 #else
269 #define wxStructStat struct _stat
270 #endif
271 #endif
272 #endif // __BORLANDC__/!__BORLANDC__
273
274
275 // functions
276
277 // MSVC and compatible compilers prepend underscores to the POSIX function
278 // names, other compilers don't and even if their later versions usually do
279 // define the versions with underscores for MSVC compatibility, it's better
280 // to avoid using them as they're not present in earlier versions and
281 // always using the native functions spelling is easier than testing for
282 // the versions
283 #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64__)
284 #define wxPOSIX_IDENT(func) ::func
285 #else // by default assume MSVC-compatible names
286 #define wxPOSIX_IDENT(func) _ ## func
287 #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
288 #endif
289
290 // first functions not working with strings, i.e. without ANSI/Unicode
291 // complications
292 #define wxClose wxPOSIX_IDENT(close)
293
294 #define wxRead wxPOSIX_IDENT(read)
295 #define wxWrite wxPOSIX_IDENT(write)
296
297 #ifdef wxHAS_HUGE_FILES
298 #ifndef __MINGW64__
299 #define wxSeek wxPOSIX_IDENT(lseeki64)
300 #define wxLseek wxPOSIX_IDENT(lseeki64)
301 #define wxTell wxPOSIX_IDENT(telli64)
302 #else
303 // unfortunately, mingw-W64 is somewhat inconsistent...
304 #define wxSeek _lseeki64
305 #define wxLseek _lseeki64
306 #define wxTell _telli64
307 #endif
308 #else // !wxHAS_HUGE_FILES
309 #define wxSeek wxPOSIX_IDENT(lseek)
310 #define wxLseek wxPOSIX_IDENT(lseek)
311 #define wxTell wxPOSIX_IDENT(tell)
312 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
313
314 #ifndef __WATCOMC__
315 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
316 // NB: this one is not POSIX and always has the underscore
317 #define wxFsync _commit
318
319 // could be already defined by configure (Cygwin)
320 #ifndef HAVE_FSYNC
321 #define HAVE_FSYNC
322 #endif
323 #endif // BORLANDC
324 #endif
325
326 #define wxEof wxPOSIX_IDENT(eof)
327
328 // then the functions taking strings
329
330 // first the ANSI versions
331 #define wxCRT_OpenA wxPOSIX_IDENT(open)
332 #define wxCRT_AccessA wxPOSIX_IDENT(access)
333 #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
334 #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
335 #ifdef wxHAS_HUGE_FILES
336 // MinGW-64 provides underscore-less versions of all file functions
337 // except for this one.
338 #ifdef __MINGW64__
339 #define wxCRT_StatA _stati64
340 #else
341 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
342 #endif
343 #else
344 // Unfortunately Watcom is not consistent
345 #if defined(__OS2__) && defined(__WATCOMC__)
346 #define wxCRT_StatA _stat
347 #else
348 #define wxCRT_StatA wxPOSIX_IDENT(stat)
349 #endif
350 #endif
351
352 // then wide char ones
353 #if wxUSE_UNICODE
354 // special workaround for buggy wopen() in bcc 5.5
355 #if defined(__BORLANDC__) && \
356 (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
357 WXDLLIMPEXP_BASE int wxCRT_OpenW(const wxChar *pathname,
358 int flags, mode_t mode);
359 #else
360 #define wxCRT_OpenW _wopen
361 #endif
362
363 #define wxCRT_AccessW _waccess
364 #define wxCRT_MkDirW _wmkdir
365 #define wxCRT_RmDirW _wrmdir
366 #ifdef wxHAS_HUGE_FILES
367 #define wxCRT_StatW _wstati64
368 #else
369 #define wxCRT_StatW _wstat
370 #endif
371 #endif // wxUSE_UNICODE
372
373
374 // finally the default char-type versions
375 #if wxUSE_UNICODE
376 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
377 // implement the missing file functions in Win9x ourselves
378 WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name,
379 int flags, int mode);
380 WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name,
381 int mode);
382 WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
383 WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
384
385 WXDLLIMPEXP_BASE int
386 wxMSLU__wstat(const wxChar *name, wxStructStat *buffer);
387
388 #define wxCRT_Open wxMSLU__wopen
389
390 #define wxCRT_Access wxMSLU__waccess
391 #define wxCRT_MkDir wxMSLU__wmkdir
392 #define wxCRT_RmDir wxMSLU__wrmdir
393 #define wxCRT_Stat wxMSLU__wstat
394 #else // !wxUSE_UNICODE_MSLU
395 #define wxCRT_Open wxCRT_OpenW
396 #define wxCRT_Access wxCRT_AccessW
397 #define wxCRT_MkDir wxCRT_MkDirW
398 #define wxCRT_RmDir wxCRT_RmDirW
399 #define wxCRT_Stat wxCRT_StatW
400 #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
401 #else // !wxUSE_UNICODE
402 #define wxCRT_Open wxCRT_OpenA
403 #define wxCRT_Access wxCRT_AccessA
404 #define wxCRT_MkDir wxCRT_MkDirA
405 #define wxCRT_RmDir wxCRT_RmDirA
406 #define wxCRT_Stat wxCRT_StatA
407 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
408
409
410 // constants (unless already defined by the user code)
411 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
412 #ifndef O_RDONLY
413 #define O_RDONLY _O_RDONLY
414 #define O_WRONLY _O_WRONLY
415 #define O_RDWR _O_RDWR
416 #define O_EXCL _O_EXCL
417 #define O_CREAT _O_CREAT
418 #define O_BINARY _O_BINARY
419 #endif
420
421 #ifndef S_IFMT
422 #define S_IFMT _S_IFMT
423 #define S_IFDIR _S_IFDIR
424 #define S_IFREG _S_IFREG
425 #endif
426 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
427
428 #ifdef wxHAS_HUGE_FILES
429 // wxFile is present and supports large files.
430 #if wxUSE_FILE
431 #define wxHAS_LARGE_FILES
432 #endif
433 // wxFFile is present and supports large files
434 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
435 #define wxHAS_LARGE_FFILES
436 #endif
437 #endif
438
439 // private defines, undefine so that nobody gets tempted to use
440 #undef wxHAS_HUGE_FILES
441 #undef wxHAS_HUGE_STDIO_FILES
442 #else // Unix or Windows using unknown compiler, assume POSIX supported
443 typedef off_t wxFileOffset;
444 #ifdef HAVE_LARGEFILE_SUPPORT
445 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
446 wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
447 BadFileSizeType );
448 // wxFile is present and supports large files
449 #if wxUSE_FILE
450 #define wxHAS_LARGE_FILES
451 #endif
452 // wxFFile is present and supports large files
453 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
454 #define wxHAS_LARGE_FFILES
455 #endif
456 #ifdef HAVE_FSEEKO
457 #define wxFseek fseeko
458 #define wxFtell ftello
459 #endif
460 #else
461 #define wxFileOffsetFmtSpec wxT("")
462 #endif
463 // functions
464 #define wxClose close
465 #define wxRead ::read
466 #define wxWrite ::write
467 #define wxLseek lseek
468 #define wxSeek lseek
469 #define wxFsync fsync
470 #define wxEof eof
471
472 #define wxCRT_MkDir mkdir
473 #define wxCRT_RmDir rmdir
474
475 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
476
477 #define wxStructStat struct stat
478
479 #define wxCRT_Open open
480 #define wxCRT_Stat stat
481 #define wxCRT_Lstat lstat
482 #define wxCRT_Access access
483
484 #define wxHAS_NATIVE_LSTAT
485 #endif // platforms
486
487 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
488 // wxCRT_Stat to avoid #ifdefs in the code using it
489 #ifndef wxHAS_NATIVE_LSTAT
490 #define wxCRT_Lstat wxCRT_Stat
491 #endif
492
493 // define wxFseek/wxFtell to large file versions if available (done above) or
494 // to fseek/ftell if not, to save ifdefs in using code
495 #ifndef wxFseek
496 #define wxFseek fseek
497 #endif
498 #ifndef wxFtell
499 #define wxFtell ftell
500 #endif
501
502 inline int wxAccess(const wxString& path, mode_t mode)
503 { return wxCRT_Access(path.fn_str(), mode); }
504 inline int wxOpen(const wxString& path, int flags, mode_t mode)
505 { return wxCRT_Open(path.fn_str(), flags, mode); }
506
507 // FIXME-CE: provide our own implementations of the missing CRT functions
508 #ifndef __WXWINCE__
509 inline int wxStat(const wxString& path, wxStructStat *buf)
510 { return wxCRT_Stat(path.fn_str(), buf); }
511 inline int wxLstat(const wxString& path, wxStructStat *buf)
512 { return wxCRT_Lstat(path.fn_str(), buf); }
513 inline int wxRmDir(const wxString& path)
514 { return wxCRT_RmDir(path.fn_str()); }
515 #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
516 || (defined(__OS2__) && defined(__WATCOMC__))
517 inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
518 { return wxCRT_MkDir(path.fn_str()); }
519 #else
520 inline int wxMkDir(const wxString& path, mode_t mode)
521 { return wxCRT_MkDir(path.fn_str(), mode); }
522 #endif
523 #endif // !__WXWINCE__
524
525 #ifdef O_BINARY
526 #define wxO_BINARY O_BINARY
527 #else
528 #define wxO_BINARY 0
529 #endif
530
531 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
532 //
533 // VisualAge C++ V4.0 cannot have any external linkage const decs
534 // in headers included by more than one primary source
535 //
536 extern const int wxInvalidOffset;
537 #else
538 const int wxInvalidOffset = -1;
539 #endif
540
541 // ----------------------------------------------------------------------------
542 // functions
543 // ----------------------------------------------------------------------------
544 WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
545
546 // does the path exist? (may have or not '/' or '\\' at the end)
547 WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
548
549 WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
550
551 // Get filename
552 WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
553 WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
554
555 // Get directory
556 WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
557
558 // all deprecated functions below are deprecated in favour of wxFileName's methods
559 #if WXWIN_COMPATIBILITY_2_8
560
561 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
562 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
563
564 wxDEPRECATED_BUT_USED_INTERNALLY(
565 WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
566 wxDEPRECATED_BUT_USED_INTERNALLY(
567 WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
568
569 // Strip the extension, in situ
570 // Deprecated in favour of wxFileName::StripExtension() but notice that their
571 // behaviour is slightly different, see the manual
572 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
573 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
574 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
575
576 // Get a temporary filename
577 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
578 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
579
580 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
581 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
582 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
583 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
584
585 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
586 // and make (if under the home tree) relative to home
587 // [caller must copy-- volatile]
588 wxDEPRECATED(
589 WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
590 const wxString& envname = wxEmptyString,
591 const wxString& user = wxEmptyString) );
592 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
593
594 // Destructive removal of /./ and /../ stuff
595 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
596 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
597 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
598 // DEPRECATED: use wxFileName::Normalize instead
599
600 // Allocate a copy of the full absolute path
601 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
602 // DEPRECATED: use wxFileName::MakeAbsolute instead
603 #endif
604
605 // Get first file name matching given wild card.
606 // Flags are reserved for future use.
607 #define wxFILE 1
608 #define wxDIR 2
609 WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
610 WXDLLIMPEXP_BASE wxString wxFindNextFile();
611
612 // Does the pattern contain wildcards?
613 WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
614
615 // Does the pattern match the text (usually a filename)?
616 // If dot_special is true, doesn't match * against . (eliminating
617 // `hidden' dot files)
618 WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
619
620 // Concatenate two files to form third
621 WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
622
623 // Copy file1 to file2
624 WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
625 bool overwrite = true);
626
627 // Remove file
628 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
629
630 // Rename file
631 WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
632
633 // Get current working directory.
634 #if WXWIN_COMPATIBILITY_2_6
635 // If buf is NULL, allocates space using new, else
636 // copies into buf.
637 // IMPORTANT NOTE getcwd is know not to work under some releases
638 // of Win32s 1.3, according to MS release notes!
639 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = NULL, int sz = 1000) );
640 // new and preferred version of wxGetWorkingDirectory
641 // NB: can't have the same name because of overloading ambiguity
642 #endif // WXWIN_COMPATIBILITY_2_6
643 WXDLLIMPEXP_BASE wxString wxGetCwd();
644
645 // Set working directory
646 WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
647
648 // Make directory
649 WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
650
651 // Remove directory. Flags reserved for future use.
652 WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
653
654 // Return the type of an open file
655 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
656 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
657
658 #if WXWIN_COMPATIBILITY_2_6
659 // compatibility defines, don't use in new code
660 wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
661 inline bool wxPathExists(const wxChar *pszPathName)
662 {
663 return wxDirExists(pszPathName);
664 }
665 #endif //WXWIN_COMPATIBILITY_2_6
666
667 // permissions; these functions work both on files and directories:
668 WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
669 WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
670 WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
671
672 // ----------------------------------------------------------------------------
673 // separators in file names
674 // ----------------------------------------------------------------------------
675
676 // between file name and extension
677 #define wxFILE_SEP_EXT wxT('.')
678
679 // between drive/volume name and the path
680 #define wxFILE_SEP_DSK wxT(':')
681
682 // between the path components
683 #define wxFILE_SEP_PATH_DOS wxT('\\')
684 #define wxFILE_SEP_PATH_UNIX wxT('/')
685 #define wxFILE_SEP_PATH_MAC wxT(':')
686 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
687
688 // separator in the path list (as in PATH environment variable)
689 // there is no PATH variable in Classic Mac OS so just use the
690 // semicolon (it must be different from the file name separator)
691 // NB: these are strings and not characters on purpose!
692 #define wxPATH_SEP_DOS wxT(";")
693 #define wxPATH_SEP_UNIX wxT(":")
694 #define wxPATH_SEP_MAC wxT(";")
695
696 // platform independent versions
697 #if defined(__UNIX__) && !defined(__OS2__)
698 // CYGWIN also uses UNIX settings
699 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
700 #define wxPATH_SEP wxPATH_SEP_UNIX
701 #elif defined(__MAC__)
702 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
703 #define wxPATH_SEP wxPATH_SEP_MAC
704 #else // Windows and OS/2
705 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
706 #define wxPATH_SEP wxPATH_SEP_DOS
707 #endif // Unix/Windows
708
709 // this is useful for wxString::IsSameAs(): to compare two file names use
710 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
711 #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
712 #define wxARE_FILENAMES_CASE_SENSITIVE true
713 #else // Windows, Mac OS and OS/2
714 #define wxARE_FILENAMES_CASE_SENSITIVE false
715 #endif // Unix/Windows
716
717 // is the char a path separator?
718 inline bool wxIsPathSeparator(wxChar c)
719 {
720 // under DOS/Windows we should understand both Unix and DOS file separators
721 #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
722 return c == wxFILE_SEP_PATH;
723 #else
724 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
725 #endif
726 }
727
728 // does the string ends with path separator?
729 WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
730
731 #if WXWIN_COMPATIBILITY_2_8
732 // split the full path into path (including drive for DOS), name and extension
733 // (understands both '/' and '\\')
734 // Deprecated in favour of wxFileName::SplitPath
735 wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
736 wxString *pstrPath,
737 wxString *pstrName,
738 wxString *pstrExt) );
739 #endif
740
741 // find a file in a list of directories, returns false if not found
742 WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
743
744 // Get the OS directory if appropriate (such as the Windows directory).
745 // On non-Windows platform, probably just return the empty string.
746 WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
747
748 #if wxUSE_DATETIME
749
750 // Get file modification time
751 WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
752
753 #endif // wxUSE_DATETIME
754
755 // Parses the wildCard, returning the number of filters.
756 // Returns 0 if none or if there's a problem,
757 // The arrays will contain an equal number of items found before the error.
758 // wildCard is in the form:
759 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
760 WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
761
762 // ----------------------------------------------------------------------------
763 // classes
764 // ----------------------------------------------------------------------------
765
766 #ifdef __UNIX__
767
768 // set umask to the given value in ctor and reset it to the old one in dtor
769 class WXDLLIMPEXP_BASE wxUmaskChanger
770 {
771 public:
772 // change the umask to the given one if it is not -1: this allows to write
773 // the same code whether you really want to change umask or not, as is in
774 // wxFileConfig::Flush() for example
775 wxUmaskChanger(int umaskNew)
776 {
777 m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
778 }
779
780 ~wxUmaskChanger()
781 {
782 if ( m_umaskOld != -1 )
783 umask((mode_t)m_umaskOld);
784 }
785
786 private:
787 int m_umaskOld;
788 };
789
790 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
791 // nothing elsewhere
792 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
793
794 #else // !__UNIX__
795
796 #define wxCHANGE_UMASK(m)
797
798 #endif // __UNIX__/!__UNIX__
799
800
801 // Path searching
802 class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
803 {
804 public:
805 wxPathList() {}
806 wxPathList(const wxArrayString &arr)
807 { Add(arr); }
808
809 // Adds all paths in environment variable
810 void AddEnvList(const wxString& envVariable);
811
812 // Adds given path to this list
813 bool Add(const wxString& path);
814 void Add(const wxArrayString &paths);
815
816 // Find the first full path for which the file exists
817 wxString FindValidPath(const wxString& filename) const;
818
819 // Find the first full path for which the file exists; ensure it's an
820 // absolute path that gets returned.
821 wxString FindAbsoluteValidPath(const wxString& filename) const;
822
823 // Given full path and filename, add path to list
824 bool EnsureFileAccessible(const wxString& path);
825
826 #if WXWIN_COMPATIBILITY_2_6
827 // Returns true if the path is in the list
828 wxDEPRECATED( bool Member(const wxString& path) const );
829 #endif
830 };
831
832 #endif // _WX_FILEFN_H_