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 #include <time.h>
18
19 #include <sys/types.h>
20 #include <sys/stat.h>
21
22 #if defined(__UNIX__)
23 #include <unistd.h>
24 #include <dirent.h>
25 #endif
26
27 #if defined(__WINDOWS__)
28 #if !defined( __GNUWIN32__ ) && !defined(__CYGWIN__)
29 #include <direct.h>
30 #include <dos.h>
31 #include <io.h>
32 #endif // __WINDOWS__
33 #endif // native Win compiler
34
35 #include <fcntl.h> // O_RDONLY &c
36
37 // ----------------------------------------------------------------------------
38 // constants
39 // ----------------------------------------------------------------------------
40
41 // MSVC doesn't define mode_t, so do it ourselves unless someone else
42 // had already predefined it.
43 #if defined(__VISUALC__) && !defined(wxHAS_MODE_T)
44 #define wxHAS_MODE_T
45 typedef int mode_t;
46 #endif
47
48 // define off_t
49 #include <sys/types.h>
50
51 #if defined(__VISUALC__)
52 typedef _off_t off_t;
53 #endif
54
55 enum wxSeekMode
56 {
57 wxFromStart,
58 wxFromCurrent,
59 wxFromEnd
60 };
61
62 enum wxFileKind
63 {
64 wxFILE_KIND_UNKNOWN,
65 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
66 wxFILE_KIND_TERMINAL, // a tty
67 wxFILE_KIND_PIPE // a pipe
68 };
69
70 // we redefine these constants here because S_IREAD &c are _not_ standard
71 // however, we do assume that the values correspond to the Unix umask bits
72 enum wxPosixPermissions
73 {
74 // standard Posix names for these permission flags:
75 wxS_IRUSR = 00400,
76 wxS_IWUSR = 00200,
77 wxS_IXUSR = 00100,
78
79 wxS_IRGRP = 00040,
80 wxS_IWGRP = 00020,
81 wxS_IXGRP = 00010,
82
83 wxS_IROTH = 00004,
84 wxS_IWOTH = 00002,
85 wxS_IXOTH = 00001,
86
87 // longer but more readable synonyms for the constants above:
88 wxPOSIX_USER_READ = wxS_IRUSR,
89 wxPOSIX_USER_WRITE = wxS_IWUSR,
90 wxPOSIX_USER_EXECUTE = wxS_IXUSR,
91
92 wxPOSIX_GROUP_READ = wxS_IRGRP,
93 wxPOSIX_GROUP_WRITE = wxS_IWGRP,
94 wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
95
96 wxPOSIX_OTHERS_READ = wxS_IROTH,
97 wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
98 wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
99
100 // default mode for the new files: allow reading/writing them to everybody but
101 // the effective file mode will be set after anding this value with umask and
102 // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
103 wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
104 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
105 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
106
107 // default mode for the new directories (see wxFileName::Mkdir): allow
108 // reading/writing/executing them to everybody, but just like wxS_DEFAULT
109 // the effective directory mode will be set after anding this value with umask
110 wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
111 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
112 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
113 };
114
115 // ----------------------------------------------------------------------------
116 // declare our versions of low level file functions: some compilers prepend
117 // underscores to the usual names, some also have Unicode versions of them
118 // ----------------------------------------------------------------------------
119
120 #if defined(__WINDOWS__) && \
121 ( \
122 defined(__VISUALC__) || \
123 defined(__MINGW64_TOOLCHAIN__) || \
124 (defined(__MINGW32__) && !defined(__WINE__)) \
125 )
126
127 // temporary defines just used immediately below
128 #undef wxHAS_HUGE_FILES
129 #undef wxHAS_HUGE_STDIO_FILES
130
131 // detect compilers which have support for huge files
132 #if defined(__VISUALC__)
133 #define wxHAS_HUGE_FILES 1
134 #elif defined(__MINGW32__)
135 #define wxHAS_HUGE_FILES 1
136 #elif defined(_LARGE_FILES)
137 #define wxHAS_HUGE_FILES 1
138 #endif
139
140 // detect compilers which have support for huge stdio files
141 #if wxCHECK_VISUALC_VERSION(8)
142 #define wxHAS_HUGE_STDIO_FILES
143 #define wxFseek _fseeki64
144 #define wxFtell _ftelli64
145 #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
146 #define wxHAS_HUGE_STDIO_FILES
147
148 wxDECL_FOR_STRICT_MINGW32(int, fseeko64, (FILE*, long long, int))
149 #define wxFseek fseeko64
150
151 #ifdef wxNEEDS_STRICT_ANSI_WORKAROUNDS
152 // Unfortunately ftello64() is not defined in the library for
153 // whatever reason but as an inline function, so define wxFtell()
154 // here similarly.
wxFtell(FILE * fp)155 inline long long wxFtell(FILE* fp)
156 {
157 fpos_t pos;
158 if ( fgetpos(fp, &pos) != 0 )
159 return -1LL;
160
161 // Unfortunately our interface assumes that the file position
162 // is representable as "long long", so we have to get it from
163 // fpos_t, even though it's an opaque type. And its exact
164 // representation has changed in MinGW, so we have to test for
165 // mingwrt version.
166 #if wxCHECK_MINGW32_VERSION(5, 2)
167 // In 5.2.2 it's a union with a __value field.
168 return pos.__value;
169 #else
170 // Up to 5.1.1 it was a simple typedef.
171 return pos;
172 #endif
173 }
174 #else
175 #define wxFtell ftello64
176 #endif
177 #endif
178
179
180 // types
181
182 #ifdef wxHAS_HUGE_FILES
183 typedef wxLongLong_t wxFileOffset;
184 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
185 #else
186 typedef off_t wxFileOffset;
187 #endif
188
189
190 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
191
192 #ifdef wxHAS_HUGE_FILES
193 #define wxStructStat struct _stati64
194 #else
195 #define wxStructStat struct _stat
196 #endif
197
198
199 // functions
200
201 // MSVC and compatible compilers prepend underscores to the POSIX function
202 // names, other compilers don't and even if their later versions usually do
203 // define the versions with underscores for MSVC compatibility, it's better
204 // to avoid using them as they're not present in earlier versions and
205 // always using the native functions spelling is easier than testing for
206 // the versions
207 #if defined(__MINGW64_TOOLCHAIN__)
208 #define wxPOSIX_IDENT(func) ::func
209 #else // by default assume MSVC-compatible names
210 #define wxPOSIX_IDENT(func) _ ## func
211 #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
212 #endif
213
214 // first functions not working with strings, i.e. without ANSI/Unicode
215 // complications
216 #define wxClose wxPOSIX_IDENT(close)
217
218 #define wxRead wxPOSIX_IDENT(read)
219 #define wxWrite wxPOSIX_IDENT(write)
220
221 #ifdef wxHAS_HUGE_FILES
222 #ifndef __MINGW64_TOOLCHAIN__
223 #define wxSeek wxPOSIX_IDENT(lseeki64)
224 #define wxLseek wxPOSIX_IDENT(lseeki64)
225 #define wxTell wxPOSIX_IDENT(telli64)
226 #else
227 // unfortunately, mingw-W64 is somewhat inconsistent...
228 #define wxSeek _lseeki64
229 #define wxLseek _lseeki64
230 #define wxTell _telli64
231 #endif
232 #else // !wxHAS_HUGE_FILES
233 #define wxSeek wxPOSIX_IDENT(lseek)
234 #define wxLseek wxPOSIX_IDENT(lseek)
235 #define wxTell wxPOSIX_IDENT(tell)
236 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
237
238
239 #define wxFsync _commit
240
241 // could be already defined by configure (Cygwin)
242 #ifndef HAVE_FSYNC
243 #define HAVE_FSYNC
244 #endif
245
246 #define wxEof wxPOSIX_IDENT(eof)
247
248 // then the functions taking strings
249
250 // first the ANSI versions
251 #define wxCRT_OpenA wxPOSIX_IDENT(open)
252 #define wxCRT_AccessA wxPOSIX_IDENT(access)
253 #define wxCRT_ChmodA wxPOSIX_IDENT(chmod)
254 #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
255 #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
256 #ifdef wxHAS_HUGE_FILES
257 // MinGW-64 provides underscore-less versions of all file functions
258 // except for this one.
259 #ifdef __MINGW64_TOOLCHAIN__
260 #define wxCRT_StatA _stati64
261 #else
262 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
263 #endif
264 #else
265 #define wxCRT_StatA wxPOSIX_IDENT(stat)
266 #endif
267
268 // then wide char ones
269 #if wxUSE_UNICODE
270
271 #define wxCRT_OpenW _wopen
272
273 wxDECL_FOR_STRICT_MINGW32(int, _wopen, (const wchar_t*, int, ...))
274 wxDECL_FOR_STRICT_MINGW32(int, _waccess, (const wchar_t*, int))
275 wxDECL_FOR_STRICT_MINGW32(int, _wchmod, (const wchar_t*, int))
276 wxDECL_FOR_STRICT_MINGW32(int, _wmkdir, (const wchar_t*))
277 wxDECL_FOR_STRICT_MINGW32(int, _wrmdir, (const wchar_t*))
278 wxDECL_FOR_STRICT_MINGW32(int, _wstati64, (const wchar_t*, struct _stati64*))
279
280 #define wxCRT_AccessW _waccess
281 #define wxCRT_ChmodW _wchmod
282 #define wxCRT_MkDirW _wmkdir
283 #define wxCRT_RmDirW _wrmdir
284 #ifdef wxHAS_HUGE_FILES
285 #define wxCRT_StatW _wstati64
286 #else
287 #define wxCRT_StatW _wstat
288 #endif
289 #endif // wxUSE_UNICODE
290
291
292 // finally the default char-type versions
293 #if wxUSE_UNICODE
294 #define wxCRT_Open wxCRT_OpenW
295 #define wxCRT_Access wxCRT_AccessW
296 #define wxCRT_Chmod wxCRT_ChmodW
297 #define wxCRT_MkDir wxCRT_MkDirW
298 #define wxCRT_RmDir wxCRT_RmDirW
299 #define wxCRT_Stat wxCRT_StatW
300 #else // !wxUSE_UNICODE
301 #define wxCRT_Open wxCRT_OpenA
302 #define wxCRT_Access wxCRT_AccessA
303 #define wxCRT_Chmod wxCRT_ChmodA
304 #define wxCRT_MkDir wxCRT_MkDirA
305 #define wxCRT_RmDir wxCRT_RmDirA
306 #define wxCRT_Stat wxCRT_StatA
307 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
308
309
310 // constants (unless already defined by the user code)
311 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
312 #ifndef O_RDONLY
313 #define O_RDONLY _O_RDONLY
314 #define O_WRONLY _O_WRONLY
315 #define O_RDWR _O_RDWR
316 #define O_EXCL _O_EXCL
317 #define O_CREAT _O_CREAT
318 #define O_BINARY _O_BINARY
319 #endif
320
321 #ifndef S_IFMT
322 #define S_IFMT _S_IFMT
323 #define S_IFDIR _S_IFDIR
324 #define S_IFREG _S_IFREG
325 #endif
326 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
327
328 #ifdef wxHAS_HUGE_FILES
329 // wxFile is present and supports large files.
330 #if wxUSE_FILE
331 #define wxHAS_LARGE_FILES
332 #endif
333 // wxFFile is present and supports large files
334 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
335 #define wxHAS_LARGE_FFILES
336 #endif
337 #endif
338
339 // private defines, undefine so that nobody gets tempted to use
340 #undef wxHAS_HUGE_FILES
341 #undef wxHAS_HUGE_STDIO_FILES
342 #else // Unix or Windows using unknown compiler, assume POSIX supported
343 typedef off_t wxFileOffset;
344 #ifdef HAVE_LARGEFILE_SUPPORT
345 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
346 wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
347 BadFileSizeType );
348 // wxFile is present and supports large files
349 #if wxUSE_FILE
350 #define wxHAS_LARGE_FILES
351 #endif
352 // wxFFile is present and supports large files
353 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
354 #define wxHAS_LARGE_FFILES
355 #endif
356 #ifdef HAVE_FSEEKO
357 #define wxFseek fseeko
358 #define wxFtell ftello
359 #endif
360 #else
361 #define wxFileOffsetFmtSpec wxT("")
362 #endif
363 // functions
364 #define wxClose close
365 #define wxRead ::read
366 #define wxWrite ::write
367 #define wxLseek lseek
368 #define wxSeek lseek
369 #define wxFsync fsync
370 #define wxEof eof
371 #define wxCRT_MkDir mkdir
372 #define wxCRT_RmDir rmdir
373
374 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
375
376 #define wxStructStat struct stat
377
378 #define wxCRT_Open open
379 #define wxCRT_Stat stat
380 #define wxCRT_Lstat lstat
381 #define wxCRT_Access access
382 #define wxCRT_Chmod chmod
383
384 #define wxCRT_Readlink readlink
385
386 #define wxHAS_NATIVE_LSTAT
387 #define wxHAS_NATIVE_READLINK
388 #endif // platforms
389
390 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
391 // wxCRT_Stat to avoid #ifdefs in the code using it
392 #ifndef wxHAS_NATIVE_LSTAT
393 #define wxCRT_Lstat wxCRT_Stat
394 #endif
395
396 // define wxFseek/wxFtell to large file versions if available (done above) or
397 // to fseek/ftell if not, to save ifdefs in using code
398 #ifndef wxFseek
399 #define wxFseek fseek
400 #endif
401 #ifndef wxFtell
402 #define wxFtell ftell
403 #endif
404
wxAccess(const wxString & path,mode_t mode)405 inline int wxAccess(const wxString& path, mode_t mode)
406 { return wxCRT_Access(path.fn_str(), mode); }
wxChmod(const wxString & path,mode_t mode)407 inline int wxChmod(const wxString& path, mode_t mode)
408 { return wxCRT_Chmod(path.fn_str(), mode); }
wxOpen(const wxString & path,int flags,mode_t mode)409 inline int wxOpen(const wxString& path, int flags, mode_t mode)
410 { return wxCRT_Open(path.fn_str(), flags, mode); }
411
412 #if defined(wxHAS_NATIVE_READLINK)
wxReadlink(const wxString & path,char * buf,int size)413 inline int wxReadlink(const wxString& path, char* buf, int size)
414 { return wxCRT_Readlink(path.fn_str(), buf, size); }
415 #endif
416
wxStat(const wxString & path,wxStructStat * buf)417 inline int wxStat(const wxString& path, wxStructStat *buf)
418 { return wxCRT_Stat(path.fn_str(), buf); }
wxLstat(const wxString & path,wxStructStat * buf)419 inline int wxLstat(const wxString& path, wxStructStat *buf)
420 { return wxCRT_Lstat(path.fn_str(), buf); }
wxRmDir(const wxString & path)421 inline int wxRmDir(const wxString& path)
422 { return wxCRT_RmDir(path.fn_str()); }
423 #if (defined(__WINDOWS__) && !defined(__CYGWIN__))
424 inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
425 { return wxCRT_MkDir(path.fn_str()); }
426 #else
wxMkDir(const wxString & path,mode_t mode)427 inline int wxMkDir(const wxString& path, mode_t mode)
428 { return wxCRT_MkDir(path.fn_str(), mode); }
429 #endif
430
431 #ifdef O_BINARY
432 #define wxO_BINARY O_BINARY
433 #else
434 #define wxO_BINARY 0
435 #endif
436
437 const int wxInvalidOffset = -1;
438
439 // ----------------------------------------------------------------------------
440 // functions
441 // ----------------------------------------------------------------------------
442 WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
443
444 // does the path exist? (may have or not '/' or '\\' at the end)
445 WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
446
447 WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
448
449 // Get filename
450 WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
451 WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
452
453 // Get directory
454 WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
455
456 // all deprecated functions below are deprecated in favour of wxFileName's methods
457 #if WXWIN_COMPATIBILITY_2_8
458
459 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
460 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
461
462 wxDEPRECATED_BUT_USED_INTERNALLY(
463 WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
464 wxDEPRECATED_BUT_USED_INTERNALLY(
465 WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
466
467 // Strip the extension, in situ
468 // Deprecated in favour of wxFileName::StripExtension() but notice that their
469 // behaviour is slightly different, see the manual
470 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
471 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
472 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
473
474 // Get a temporary filename
475 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
476 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
477
478 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
479 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
480 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
481 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
482
483 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
484 // and make (if under the home tree) relative to home
485 // [caller must copy-- volatile]
486 wxDEPRECATED(
487 WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
488 const wxString& envname = wxEmptyString,
489 const wxString& user = wxEmptyString) );
490 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
491
492 // Destructive removal of /./ and /../ stuff
493 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
494 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
495 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
496 // DEPRECATED: use wxFileName::Normalize instead
497
498 // Allocate a copy of the full absolute path
499 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
500 // DEPRECATED: use wxFileName::MakeAbsolute instead
501 #endif
502
503 // Get first file name matching given wild card.
504 // Flags are reserved for future use.
505 #define wxFILE 1
506 #define wxDIR 2
507 WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
508 WXDLLIMPEXP_BASE wxString wxFindNextFile();
509
510 // Does the pattern contain wildcards?
511 WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
512
513 // Does the pattern match the text (usually a filename)?
514 // If dot_special is true, doesn't match * against . (eliminating
515 // `hidden' dot files)
516 WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
517
518 // Concatenate two files to form third
519 WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& src1, const wxString& src2, const wxString& dest);
520
521 // Copy file
522 WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& src, const wxString& dest,
523 bool overwrite = true);
524
525 // Remove file
526 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
527
528 // Rename file
529 WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& oldpath, const wxString& newpath, bool overwrite = true);
530
531 // Get current working directory.
532 WXDLLIMPEXP_BASE wxString wxGetCwd();
533
534 // Set working directory
535 WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
536
537 // Make directory
538 WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
539
540 // Remove directory. Flags reserved for future use.
541 WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
542
543 // Return the type of an open file
544 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
545 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
546
547 // permissions; these functions work both on files and directories:
548 WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
549 WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
550 WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
551
552 // ----------------------------------------------------------------------------
553 // separators in file names
554 // ----------------------------------------------------------------------------
555
556 // between file name and extension
557 #define wxFILE_SEP_EXT wxT('.')
558
559 // between drive/volume name and the path
560 #define wxFILE_SEP_DSK wxT(':')
561
562 // between the path components
563 #define wxFILE_SEP_PATH_DOS wxT('\\')
564 #define wxFILE_SEP_PATH_UNIX wxT('/')
565 #define wxFILE_SEP_PATH_MAC wxT(':')
566 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
567
568 // separator in the path list (as in PATH environment variable)
569 // there is no PATH variable in Classic Mac OS so just use the
570 // semicolon (it must be different from the file name separator)
571 // NB: these are strings and not characters on purpose!
572 #define wxPATH_SEP_DOS wxT(";")
573 #define wxPATH_SEP_UNIX wxT(":")
574 #define wxPATH_SEP_MAC wxT(";")
575
576 // platform independent versions
577 #if defined(__UNIX__)
578 // CYGWIN also uses UNIX settings
579 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
580 #define wxPATH_SEP wxPATH_SEP_UNIX
581 #elif defined(__MAC__)
582 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
583 #define wxPATH_SEP wxPATH_SEP_MAC
584 #else // Windows
585 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
586 #define wxPATH_SEP wxPATH_SEP_DOS
587 #endif // Unix/Windows
588
589 // this is useful for wxString::IsSameAs(): to compare two file names use
590 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
591 #if defined(__UNIX__) && !defined(__DARWIN__)
592 #define wxARE_FILENAMES_CASE_SENSITIVE true
593 #else // Windows and OSX
594 #define wxARE_FILENAMES_CASE_SENSITIVE false
595 #endif // Unix/Windows
596
597 // is the char a path separator?
wxIsPathSeparator(wxChar c)598 inline bool wxIsPathSeparator(wxChar c)
599 {
600 // under DOS/Windows we should understand both Unix and DOS file separators
601 #if defined(__UNIX__) || defined(__MAC__)
602 return c == wxFILE_SEP_PATH;
603 #else
604 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
605 #endif
606 }
607
608 // does the string ends with path separator?
609 WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
610
611 #if WXWIN_COMPATIBILITY_2_8
612 // split the full path into path (including drive for DOS), name and extension
613 // (understands both '/' and '\\')
614 // Deprecated in favour of wxFileName::SplitPath
615 wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
616 wxString *pstrPath,
617 wxString *pstrName,
618 wxString *pstrExt) );
619 #endif
620
621 // find a file in a list of directories, returns false if not found
622 WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
623
624 // Get the OS directory if appropriate (such as the Windows directory).
625 // On non-Windows platform, probably just return the empty string.
626 WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
627
628 #if wxUSE_DATETIME
629
630 // Get file modification time
631 WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
632
633 #endif // wxUSE_DATETIME
634
635 // Parses the wildCard, returning the number of filters.
636 // Returns 0 if none or if there's a problem,
637 // The arrays will contain an equal number of items found before the error.
638 // wildCard is in the form:
639 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
640 WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
641
642 // ----------------------------------------------------------------------------
643 // classes
644 // ----------------------------------------------------------------------------
645
646 #ifdef __UNIX__
647
648 // set umask to the given value in ctor and reset it to the old one in dtor
649 class WXDLLIMPEXP_BASE wxUmaskChanger
650 {
651 public:
652 // change the umask to the given one if it is not -1: this allows to write
653 // the same code whether you really want to change umask or not, as is in
654 // wxFileConfig::Flush() for example
wxUmaskChanger(int umaskNew)655 wxUmaskChanger(int umaskNew)
656 {
657 m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
658 }
659
~wxUmaskChanger()660 ~wxUmaskChanger()
661 {
662 if ( m_umaskOld != -1 )
663 umask((mode_t)m_umaskOld);
664 }
665
666 private:
667 int m_umaskOld;
668 };
669
670 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
671 // nothing elsewhere
672 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
673
674 #else // !__UNIX__
675
676 #define wxCHANGE_UMASK(m)
677
678 #endif // __UNIX__/!__UNIX__
679
680
681 // Path searching
682 class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
683 {
684 public:
wxPathList()685 wxPathList() {}
wxPathList(const wxArrayString & arr)686 wxPathList(const wxArrayString &arr)
687 { Add(arr); }
688
689 // Adds all paths in environment variable
690 void AddEnvList(const wxString& envVariable);
691
692 // Adds given path to this list
693 bool Add(const wxString& path);
694 void Add(const wxArrayString &paths);
695
696 // Find the first full path for which the file exists
697 wxString FindValidPath(const wxString& filename) const;
698
699 // Find the first full path for which the file exists; ensure it's an
700 // absolute path that gets returned.
701 wxString FindAbsoluteValidPath(const wxString& filename) const;
702
703 // Given full path and filename, add path to list
704 bool EnsureFileAccessible(const wxString& path);
705 };
706
707 #endif // _WX_FILEFN_H_
708