1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
7 // Copyright: (c) 1998 Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/arrstr.h"
18 #include "wx/msw/wince/time.h"
19 #include "wx/msw/private.h"
25 #include <sys/types.h>
30 // need to check for __OS2__ first since currently both
31 // __OS2__ and __UNIX__ are defined.
33 #include "wx/os2/private.h"
41 #elif defined(__UNIX__)
46 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
47 #if !defined( __GNUWIN32__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
52 #endif // native Win compiler
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.
73 #include <fcntl.h> // O_RDONLY &c
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 #if defined(__VISUALC__) || defined(__INTELC__) || defined(__DIGITALMARS__)
88 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
89 #include <sys/types.h>
95 #if (defined(__VISUALC__) && !defined(__WXWINCE__)) || (defined(__WINDOWS__) && defined (__INTELC__))
97 #elif defined(__SYMANTEC__)
111 wxFILE_KIND_DISK
, // a file supporting seeking to arbitrary offsets
112 wxFILE_KIND_TERMINAL
, // a tty
113 wxFILE_KIND_PIPE
// a pipe
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
120 // standard Posix names for these permission flags:
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
,
138 wxPOSIX_GROUP_READ
= wxS_IRGRP
,
139 wxPOSIX_GROUP_WRITE
= wxS_IWGRP
,
140 wxPOSIX_GROUP_EXECUTE
= wxS_IXGRP
,
142 wxPOSIX_OTHERS_READ
= wxS_IROTH
,
143 wxPOSIX_OTHERS_WRITE
= wxS_IWOTH
,
144 wxPOSIX_OTHERS_EXECUTE
= wxS_IXOTH
,
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
),
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
)
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 // ----------------------------------------------------------------------------
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
);
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__)) && \
190 (defined(__VISUALC__) || (defined(__WINDOWS__) && defined (__INTELC__))) || \
191 defined(__MINGW64__) || \
192 (defined(__MINGW32__) && !defined(__WINE__) && \
193 wxCHECK_W32API_VERSION(0, 5)) || \
194 defined(__DMC__) || \
195 defined(__WATCOMC__) || \
196 defined(__BORLANDC__) \
199 // temporary defines just used immediately below
200 #undef wxHAS_HUGE_FILES
201 #undef wxHAS_HUGE_STDIO_FILES
203 // detect compilers which have support for huge files
204 #if (defined(__VISUALC__) || (defined(__WINDOWS__) && defined (__INTELC__)))
205 #define wxHAS_HUGE_FILES 1
206 #elif defined(__MINGW32__) || defined(__MINGW64__)
207 #define wxHAS_HUGE_FILES 1f
208 #elif defined(_LARGE_FILES)
209 #define wxHAS_HUGE_FILES 1
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 #define wxFseek fseeko64
220 #define wxFtell ftello64
223 // other Windows compilers (DMC, Watcom, and Borland) don't have huge file
224 // support (or at least not all functions needed for it by wx) currently
228 #ifdef wxHAS_HUGE_FILES
229 typedef wxLongLong_t wxFileOffset
;
230 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
232 typedef off_t wxFileOffset
;
235 // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
236 // resolution operator present in wxPOSIX_IDENT for it
238 #define wxPOSIX_STRUCT(s) struct s
240 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
243 // Notice that Watcom is the only compiler to have a wide char
244 // version of struct stat as well as a wide char stat function variant.
245 // This was dropped since OW 1.4 "for consistency across platforms".
247 // Borland is also special in that it uses _stat with Unicode functions
248 // (for MSVC compatibility?) but stat with ANSI ones
251 #define wxStructStat struct stati64
254 #define wxStructStat struct _stat
256 #define wxStructStat struct stat
259 #else // !__BORLANDC__
260 #ifdef wxHAS_HUGE_FILES
261 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
262 #define wxStructStat struct _wstati64
264 #define wxStructStat struct _stati64
267 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
268 #define wxStructStat struct _wstat
270 #define wxStructStat struct _stat
273 #endif // __BORLANDC__/!__BORLANDC__
278 // MSVC and compatible compilers prepend underscores to the POSIX function
279 // names, other compilers don't and even if their later versions usually do
280 // define the versions with underscores for MSVC compatibility, it's better
281 // to avoid using them as they're not present in earlier versions and
282 // always using the native functions spelling is easier than testing for
284 #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64__)
285 #define wxPOSIX_IDENT(func) ::func
286 #else // by default assume MSVC-compatible names
287 #define wxPOSIX_IDENT(func) _ ## func
288 #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
291 // first functions not working with strings, i.e. without ANSI/Unicode
293 #define wxClose wxPOSIX_IDENT(close)
295 #define wxRead wxPOSIX_IDENT(read)
296 #define wxWrite wxPOSIX_IDENT(write)
298 #ifdef wxHAS_HUGE_FILES
300 #define wxSeek wxPOSIX_IDENT(lseeki64)
301 #define wxLseek wxPOSIX_IDENT(lseeki64)
302 #define wxTell wxPOSIX_IDENT(telli64)
304 // unfortunately, mingw-W64 is somewhat inconsistent...
305 #define wxSeek _lseeki64
306 #define wxLseek _lseeki64
307 #define wxTell _telli64
309 #else // !wxHAS_HUGE_FILES
310 #define wxSeek wxPOSIX_IDENT(lseek)
311 #define wxLseek wxPOSIX_IDENT(lseek)
312 #define wxTell wxPOSIX_IDENT(tell)
313 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
316 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
317 // NB: this one is not POSIX and always has the underscore
318 #define wxFsync _commit
320 // could be already defined by configure (Cygwin)
327 #define wxEof wxPOSIX_IDENT(eof)
329 // then the functions taking strings
331 // first the ANSI versions
332 #define wxCRT_OpenA wxPOSIX_IDENT(open)
333 #define wxCRT_AccessA wxPOSIX_IDENT(access)
334 #define wxCRT_ChmodA wxPOSIX_IDENT(chmod)
335 #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
336 #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
337 #ifdef wxHAS_HUGE_FILES
338 // MinGW-64 provides underscore-less versions of all file functions
339 // except for this one.
341 #define wxCRT_StatA _stati64
343 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
346 // Unfortunately Watcom is not consistent
347 #if defined(__OS2__) && defined(__WATCOMC__)
348 #define wxCRT_StatA _stat
350 #define wxCRT_StatA wxPOSIX_IDENT(stat)
354 // then wide char ones
356 // special workaround for buggy wopen() in bcc 5.5
357 #if defined(__BORLANDC__) && \
358 (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
359 WXDLLIMPEXP_BASE
int wxCRT_OpenW(const wxChar
*pathname
,
360 int flags
, mode_t mode
);
362 #define wxCRT_OpenW _wopen
365 #define wxCRT_AccessW _waccess
366 #define wxCRT_ChmodW _wchmod
367 #define wxCRT_MkDirW _wmkdir
368 #define wxCRT_RmDirW _wrmdir
369 #ifdef wxHAS_HUGE_FILES
370 #define wxCRT_StatW _wstati64
372 #define wxCRT_StatW _wstat
374 #endif // wxUSE_UNICODE
377 // finally the default char-type versions
379 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
380 // implement the missing file functions in Win9x ourselves
381 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wxChar
*name
,
382 int flags
, int mode
);
383 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wxChar
*name
,
385 WXDLLIMPEXP_BASE
int wxMSLU__wchmod(const wxChar
*name
,
387 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wxChar
*name
);
388 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wxChar
*name
);
391 wxMSLU__wstat(const wxChar
*name
, wxStructStat
*buffer
);
393 #define wxCRT_Open wxMSLU__wopen
395 #define wxCRT_Access wxMSLU__waccess
396 #define wxCRT_Chmod wxMSLU__wchmod
397 #define wxCRT_MkDir wxMSLU__wmkdir
398 #define wxCRT_RmDir wxMSLU__wrmdir
399 #define wxCRT_Stat wxMSLU__wstat
400 #else // !wxUSE_UNICODE_MSLU
401 #define wxCRT_Open wxCRT_OpenW
402 #define wxCRT_Access wxCRT_AccessW
403 #define wxCRT_Chmod wxCRT_ChmodW
404 #define wxCRT_MkDir wxCRT_MkDirW
405 #define wxCRT_RmDir wxCRT_RmDirW
406 #define wxCRT_Stat wxCRT_StatW
407 #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
408 #else // !wxUSE_UNICODE
409 #define wxCRT_Open wxCRT_OpenA
410 #define wxCRT_Access wxCRT_AccessA
411 #define wxCRT_Chmod wxCRT_ChmodA
412 #define wxCRT_MkDir wxCRT_MkDirA
413 #define wxCRT_RmDir wxCRT_RmDirA
414 #define wxCRT_Stat wxCRT_StatA
415 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
418 // constants (unless already defined by the user code)
419 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
421 #define O_RDONLY _O_RDONLY
422 #define O_WRONLY _O_WRONLY
423 #define O_RDWR _O_RDWR
424 #define O_EXCL _O_EXCL
425 #define O_CREAT _O_CREAT
426 #define O_BINARY _O_BINARY
430 #define S_IFMT _S_IFMT
431 #define S_IFDIR _S_IFDIR
432 #define S_IFREG _S_IFREG
434 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
436 #ifdef wxHAS_HUGE_FILES
437 // wxFile is present and supports large files.
439 #define wxHAS_LARGE_FILES
441 // wxFFile is present and supports large files
442 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
443 #define wxHAS_LARGE_FFILES
447 // private defines, undefine so that nobody gets tempted to use
448 #undef wxHAS_HUGE_FILES
449 #undef wxHAS_HUGE_STDIO_FILES
450 #else // Unix or Windows using unknown compiler, assume POSIX supported
451 typedef off_t wxFileOffset
;
452 #ifdef HAVE_LARGEFILE_SUPPORT
453 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
454 wxCOMPILE_TIME_ASSERT( sizeof(off_t
) == sizeof(wxLongLong_t
),
456 // wxFile is present and supports large files
458 #define wxHAS_LARGE_FILES
460 // wxFFile is present and supports large files
461 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
462 #define wxHAS_LARGE_FFILES
465 #define wxFseek fseeko
466 #define wxFtell ftello
469 #define wxFileOffsetFmtSpec wxT("")
472 #define wxClose close
473 #define wxRead ::read
474 #define wxWrite ::write
475 #define wxLseek lseek
477 #define wxFsync fsync
479 #define wxCRT_MkDir mkdir
480 #define wxCRT_RmDir rmdir
482 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
484 #define wxStructStat struct stat
486 #define wxCRT_Open open
487 #define wxCRT_Stat stat
488 #define wxCRT_Lstat lstat
489 #define wxCRT_Access access
490 #define wxCRT_Chmod chmod
492 #define wxHAS_NATIVE_LSTAT
495 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
496 // wxCRT_Stat to avoid #ifdefs in the code using it
497 #ifndef wxHAS_NATIVE_LSTAT
498 #define wxCRT_Lstat wxCRT_Stat
501 // define wxFseek/wxFtell to large file versions if available (done above) or
502 // to fseek/ftell if not, to save ifdefs in using code
504 #define wxFseek fseek
507 #define wxFtell ftell
510 inline int wxAccess(const wxString
& path
, mode_t mode
)
511 { return wxCRT_Access(path
.fn_str(), mode
); }
512 inline int wxChmod(const wxString
& path
, mode_t mode
)
513 { return wxCRT_Chmod(path
.fn_str(), mode
); }
514 inline int wxOpen(const wxString
& path
, int flags
, mode_t mode
)
515 { return wxCRT_Open(path
.fn_str(), flags
, mode
); }
517 // FIXME-CE: provide our own implementations of the missing CRT functions
519 inline int wxStat(const wxString
& path
, wxStructStat
*buf
)
520 { return wxCRT_Stat(path
.fn_str(), buf
); }
521 inline int wxLstat(const wxString
& path
, wxStructStat
*buf
)
522 { return wxCRT_Lstat(path
.fn_str(), buf
); }
523 inline int wxRmDir(const wxString
& path
)
524 { return wxCRT_RmDir(path
.fn_str()); }
525 #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
526 || (defined(__OS2__) && defined(__WATCOMC__))
527 inline int wxMkDir(const wxString
& path
, mode_t
WXUNUSED(mode
) = 0)
528 { return wxCRT_MkDir(path
.fn_str()); }
530 inline int wxMkDir(const wxString
& path
, mode_t mode
)
531 { return wxCRT_MkDir(path
.fn_str(), mode
); }
533 #endif // !__WXWINCE__
536 #define wxO_BINARY O_BINARY
541 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
543 // VisualAge C++ V4.0 cannot have any external linkage const decs
544 // in headers included by more than one primary source
546 extern const int wxInvalidOffset
;
548 const int wxInvalidOffset
= -1;
551 // ----------------------------------------------------------------------------
553 // ----------------------------------------------------------------------------
554 WXDLLIMPEXP_BASE
bool wxFileExists(const wxString
& filename
);
556 // does the path exist? (may have or not '/' or '\\' at the end)
557 WXDLLIMPEXP_BASE
bool wxDirExists(const wxString
& pathName
);
559 WXDLLIMPEXP_BASE
bool wxIsAbsolutePath(const wxString
& filename
);
562 WXDLLIMPEXP_BASE wxChar
* wxFileNameFromPath(wxChar
*path
);
563 WXDLLIMPEXP_BASE wxString
wxFileNameFromPath(const wxString
& path
);
566 WXDLLIMPEXP_BASE wxString
wxPathOnly(const wxString
& path
);
568 // all deprecated functions below are deprecated in favour of wxFileName's methods
569 #if WXWIN_COMPATIBILITY_2_8
571 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxDos2UnixFilename(char *s
) );
572 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxDos2UnixFilename(wchar_t *s
) );
574 wxDEPRECATED_BUT_USED_INTERNALLY(
575 WXDLLIMPEXP_BASE
void wxUnix2DosFilename(char *s
) );
576 wxDEPRECATED_BUT_USED_INTERNALLY(
577 WXDLLIMPEXP_BASE
void wxUnix2DosFilename(wchar_t *s
) );
579 // Strip the extension, in situ
580 // Deprecated in favour of wxFileName::StripExtension() but notice that their
581 // behaviour is slightly different, see the manual
582 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(char *buffer
) );
583 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(wchar_t *buffer
) );
584 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(wxString
& buffer
) );
586 // Get a temporary filename
587 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar
* wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
= NULL
) );
588 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
) );
590 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
591 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
char* wxExpandPath(char *dest
, const wxString
& path
) );
592 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
wchar_t* wxExpandPath(wchar_t *dest
, const wxString
& path
) );
593 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
595 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
596 // and make (if under the home tree) relative to home
597 // [caller must copy-- volatile]
599 WXDLLIMPEXP_BASE wxChar
* wxContractPath(const wxString
& filename
,
600 const wxString
& envname
= wxEmptyString
,
601 const wxString
& user
= wxEmptyString
) );
602 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
604 // Destructive removal of /./ and /../ stuff
605 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
char* wxRealPath(char *path
) );
606 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
wchar_t* wxRealPath(wchar_t *path
) );
607 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString
wxRealPath(const wxString
& path
) );
608 // DEPRECATED: use wxFileName::Normalize instead
610 // Allocate a copy of the full absolute path
611 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar
* wxCopyAbsolutePath(const wxString
& path
) );
612 // DEPRECATED: use wxFileName::MakeAbsolute instead
615 // Get first file name matching given wild card.
616 // Flags are reserved for future use.
619 WXDLLIMPEXP_BASE wxString
wxFindFirstFile(const wxString
& spec
, int flags
= wxFILE
);
620 WXDLLIMPEXP_BASE wxString
wxFindNextFile();
622 // Does the pattern contain wildcards?
623 WXDLLIMPEXP_BASE
bool wxIsWild(const wxString
& pattern
);
625 // Does the pattern match the text (usually a filename)?
626 // If dot_special is true, doesn't match * against . (eliminating
627 // `hidden' dot files)
628 WXDLLIMPEXP_BASE
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= true);
630 // Concatenate two files to form third
631 WXDLLIMPEXP_BASE
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
633 // Copy file1 to file2
634 WXDLLIMPEXP_BASE
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
,
635 bool overwrite
= true);
638 WXDLLIMPEXP_BASE
bool wxRemoveFile(const wxString
& file
);
641 WXDLLIMPEXP_BASE
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
= true);
643 // Get current working directory.
644 #if WXWIN_COMPATIBILITY_2_6
645 // If buf is NULL, allocates space using new, else
647 // IMPORTANT NOTE getcwd is know not to work under some releases
648 // of Win32s 1.3, according to MS release notes!
649 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar
* wxGetWorkingDirectory(wxChar
*buf
= NULL
, int sz
= 1000) );
650 // new and preferred version of wxGetWorkingDirectory
651 // NB: can't have the same name because of overloading ambiguity
652 #endif // WXWIN_COMPATIBILITY_2_6
653 WXDLLIMPEXP_BASE wxString
wxGetCwd();
655 // Set working directory
656 WXDLLIMPEXP_BASE
bool wxSetWorkingDirectory(const wxString
& d
);
659 WXDLLIMPEXP_BASE
bool wxMkdir(const wxString
& dir
, int perm
= wxS_DIR_DEFAULT
);
661 // Remove directory. Flags reserved for future use.
662 WXDLLIMPEXP_BASE
bool wxRmdir(const wxString
& dir
, int flags
= 0);
664 // Return the type of an open file
665 WXDLLIMPEXP_BASE wxFileKind
wxGetFileKind(int fd
);
666 WXDLLIMPEXP_BASE wxFileKind
wxGetFileKind(FILE *fp
);
668 #if WXWIN_COMPATIBILITY_2_6
669 // compatibility defines, don't use in new code
670 wxDEPRECATED( inline bool wxPathExists(const wxChar
*pszPathName
) );
671 inline bool wxPathExists(const wxChar
*pszPathName
)
673 return wxDirExists(pszPathName
);
675 #endif //WXWIN_COMPATIBILITY_2_6
677 // permissions; these functions work both on files and directories:
678 WXDLLIMPEXP_BASE
bool wxIsWritable(const wxString
&path
);
679 WXDLLIMPEXP_BASE
bool wxIsReadable(const wxString
&path
);
680 WXDLLIMPEXP_BASE
bool wxIsExecutable(const wxString
&path
);
682 // ----------------------------------------------------------------------------
683 // separators in file names
684 // ----------------------------------------------------------------------------
686 // between file name and extension
687 #define wxFILE_SEP_EXT wxT('.')
689 // between drive/volume name and the path
690 #define wxFILE_SEP_DSK wxT(':')
692 // between the path components
693 #define wxFILE_SEP_PATH_DOS wxT('\\')
694 #define wxFILE_SEP_PATH_UNIX wxT('/')
695 #define wxFILE_SEP_PATH_MAC wxT(':')
696 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
698 // separator in the path list (as in PATH environment variable)
699 // there is no PATH variable in Classic Mac OS so just use the
700 // semicolon (it must be different from the file name separator)
701 // NB: these are strings and not characters on purpose!
702 #define wxPATH_SEP_DOS wxT(";")
703 #define wxPATH_SEP_UNIX wxT(":")
704 #define wxPATH_SEP_MAC wxT(";")
706 // platform independent versions
707 #if defined(__UNIX__) && !defined(__OS2__)
708 // CYGWIN also uses UNIX settings
709 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
710 #define wxPATH_SEP wxPATH_SEP_UNIX
711 #elif defined(__MAC__)
712 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
713 #define wxPATH_SEP wxPATH_SEP_MAC
714 #else // Windows and OS/2
715 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
716 #define wxPATH_SEP wxPATH_SEP_DOS
717 #endif // Unix/Windows
719 // this is useful for wxString::IsSameAs(): to compare two file names use
720 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
721 #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
722 #define wxARE_FILENAMES_CASE_SENSITIVE true
723 #else // Windows, Mac OS and OS/2
724 #define wxARE_FILENAMES_CASE_SENSITIVE false
725 #endif // Unix/Windows
727 // is the char a path separator?
728 inline bool wxIsPathSeparator(wxChar c
)
730 // under DOS/Windows we should understand both Unix and DOS file separators
731 #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
732 return c
== wxFILE_SEP_PATH
;
734 return c
== wxFILE_SEP_PATH_DOS
|| c
== wxFILE_SEP_PATH_UNIX
;
738 // does the string ends with path separator?
739 WXDLLIMPEXP_BASE
bool wxEndsWithPathSeparator(const wxString
& filename
);
741 #if WXWIN_COMPATIBILITY_2_8
742 // split the full path into path (including drive for DOS), name and extension
743 // (understands both '/' and '\\')
744 // Deprecated in favour of wxFileName::SplitPath
745 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxSplitPath(const wxString
& fileName
,
748 wxString
*pstrExt
) );
751 // find a file in a list of directories, returns false if not found
752 WXDLLIMPEXP_BASE
bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
);
754 // Get the OS directory if appropriate (such as the Windows directory).
755 // On non-Windows platform, probably just return the empty string.
756 WXDLLIMPEXP_BASE wxString
wxGetOSDirectory();
760 // Get file modification time
761 WXDLLIMPEXP_BASE
time_t wxFileModificationTime(const wxString
& filename
);
763 #endif // wxUSE_DATETIME
765 // Parses the wildCard, returning the number of filters.
766 // Returns 0 if none or if there's a problem,
767 // The arrays will contain an equal number of items found before the error.
768 // wildCard is in the form:
769 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
770 WXDLLIMPEXP_BASE
int wxParseCommonDialogsFilter(const wxString
& wildCard
, wxArrayString
& descriptions
, wxArrayString
& filters
);
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
778 // set umask to the given value in ctor and reset it to the old one in dtor
779 class WXDLLIMPEXP_BASE wxUmaskChanger
782 // change the umask to the given one if it is not -1: this allows to write
783 // the same code whether you really want to change umask or not, as is in
784 // wxFileConfig::Flush() for example
785 wxUmaskChanger(int umaskNew
)
787 m_umaskOld
= umaskNew
== -1 ? -1 : (int)umask((mode_t
)umaskNew
);
792 if ( m_umaskOld
!= -1 )
793 umask((mode_t
)m_umaskOld
);
800 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
802 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
806 #define wxCHANGE_UMASK(m)
808 #endif // __UNIX__/!__UNIX__
812 class WXDLLIMPEXP_BASE wxPathList
: public wxArrayString
816 wxPathList(const wxArrayString
&arr
)
819 // Adds all paths in environment variable
820 void AddEnvList(const wxString
& envVariable
);
822 // Adds given path to this list
823 bool Add(const wxString
& path
);
824 void Add(const wxArrayString
&paths
);
826 // Find the first full path for which the file exists
827 wxString
FindValidPath(const wxString
& filename
) const;
829 // Find the first full path for which the file exists; ensure it's an
830 // absolute path that gets returned.
831 wxString
FindAbsoluteValidPath(const wxString
& filename
) const;
833 // Given full path and filename, add path to list
834 bool EnsureFileAccessible(const wxString
& path
);
836 #if WXWIN_COMPATIBILITY_2_6
837 // Returns true if the path is in the list
838 wxDEPRECATED( bool Member(const wxString
& path
) const );
842 #endif // _WX_FILEFN_H_