1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/arrstr.h"
19 #include "wx/msw/wince/time.h"
20 #include "wx/msw/private.h"
27 #elif !defined(__MWERKS__)
28 #include <sys/types.h>
32 #include <sys/types.h>
44 // need to check for __OS2__ first since currently both
45 // __OS2__ and __UNIX__ are defined.
47 #include "wx/os2/private.h"
55 #elif defined(__UNIX__)
60 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
61 #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
66 #endif // native Win compiler
80 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
81 // this (3.1 I believe) and how to test for it.
82 // If this works for Borland 4.0 as well, then no worries.
87 #include <fcntl.h> // O_RDONLY &c
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 #if defined(__VISUALC__) || defined(__DIGITALMARS__)
102 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
103 #include <sys/types.h>
109 #if (defined(__VISUALC__) && !defined(__WXWINCE__)) || ( defined(__MWERKS__) && defined( __INTEL__) )
110 typedef _off_t off_t
;
111 #elif defined(__SYMANTEC__)
113 #elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
127 wxFILE_KIND_DISK
, // a file supporting seeking to arbitrary offsets
128 wxFILE_KIND_TERMINAL
, // a tty
129 wxFILE_KIND_PIPE
// a pipe
132 // we redefine these constants here because S_IREAD &c are _not_ standard
133 // however, we do assume that the values correspond to the Unix umask bits
134 enum wxPosixPermissions
136 // standard Posix names for these permission flags:
149 // longer but more readable synonyms for the constants above:
150 wxPOSIX_USER_READ
= wxS_IRUSR
,
151 wxPOSIX_USER_WRITE
= wxS_IWUSR
,
152 wxPOSIX_USER_EXECUTE
= wxS_IXUSR
,
154 wxPOSIX_GROUP_READ
= wxS_IRGRP
,
155 wxPOSIX_GROUP_WRITE
= wxS_IWGRP
,
156 wxPOSIX_GROUP_EXECUTE
= wxS_IXGRP
,
158 wxPOSIX_OTHERS_READ
= wxS_IROTH
,
159 wxPOSIX_OTHERS_WRITE
= wxS_IWOTH
,
160 wxPOSIX_OTHERS_EXECUTE
= wxS_IXOTH
,
162 // default mode for the new files: allow reading/writing them to everybody but
163 // the effective file mode will be set after anding this value with umask and
164 // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
165 wxS_DEFAULT
= (wxPOSIX_USER_READ
| wxPOSIX_USER_WRITE
| \
166 wxPOSIX_GROUP_READ
| wxPOSIX_GROUP_WRITE
| \
167 wxPOSIX_OTHERS_READ
| wxPOSIX_OTHERS_WRITE
),
169 // default mode for the new directories (see wxFileName::Mkdir): allow
170 // reading/writing/executing them to everybody, but just like wxS_DEFAULT
171 // the effective directory mode will be set after anding this value with umask
172 wxS_DIR_DEFAULT
= (wxPOSIX_USER_READ
| wxPOSIX_USER_WRITE
| wxPOSIX_USER_EXECUTE
| \
173 wxPOSIX_GROUP_READ
| wxPOSIX_GROUP_WRITE
| wxPOSIX_GROUP_EXECUTE
| \
174 wxPOSIX_OTHERS_READ
| wxPOSIX_OTHERS_WRITE
| wxPOSIX_OTHERS_EXECUTE
)
177 // ----------------------------------------------------------------------------
178 // declare our versions of low level file functions: some compilers prepend
179 // underscores to the usual names, some also have Unicode versions of them
180 // ----------------------------------------------------------------------------
182 // Wrappers around Win32 api functions like CreateFile, ReadFile and such
183 // Implemented in filefnwce.cpp
184 #if defined( __WXWINCE__)
185 typedef __int64 wxFileOffset
;
186 #define wxFileOffsetFmtSpec wxT("I64")
187 WXDLLIMPEXP_BASE
int wxCRT_Open(const wxChar
*filename
, int oflag
, int WXUNUSED(pmode
));
188 WXDLLIMPEXP_BASE
int wxCRT_Access(const wxChar
*name
, int WXUNUSED(how
));
189 WXDLLIMPEXP_BASE
int wxClose(int fd
);
190 WXDLLIMPEXP_BASE
int wxFsync(int WXUNUSED(fd
));
191 WXDLLIMPEXP_BASE
int wxRead(int fd
, void *buf
, unsigned int count
);
192 WXDLLIMPEXP_BASE
int wxWrite(int fd
, const void *buf
, unsigned int count
);
193 WXDLLIMPEXP_BASE
int wxEof(int fd
);
194 WXDLLIMPEXP_BASE wxFileOffset
wxSeek(int fd
, wxFileOffset offset
, int origin
);
195 #define wxLSeek wxSeek
196 WXDLLIMPEXP_BASE wxFileOffset
wxTell(int fd
);
198 // always Unicode under WinCE
199 #define wxCRT_MkDir _wmkdir
200 #define wxCRT_RmDir _wrmdir
201 #define wxCRT_Stat _wstat
202 #define wxStructStat struct _stat
203 #elif (defined(__WXMSW__) || defined(__OS2__)) && \
205 defined(__VISUALC__) || \
206 defined(__MINGW64__) || \
207 (defined(__MINGW32__) && !defined(__WINE__) && \
208 wxCHECK_W32API_VERSION(0, 5)) || \
209 defined(__MWERKS__) || \
210 defined(__DMC__) || \
211 defined(__WATCOMC__) || \
212 defined(__BORLANDC__) \
215 // temporary defines just used immediately below
216 #undef wxHAS_HUGE_FILES
217 #undef wxHAS_HUGE_STDIO_FILES
219 // detect compilers which have support for huge files
220 #if defined(__VISUALC__)
221 #define wxHAS_HUGE_FILES 1
222 #elif defined(__MINGW32__) || defined(__MINGW64__)
223 #define wxHAS_HUGE_FILES 1
224 #elif defined(_LARGE_FILES)
225 #define wxHAS_HUGE_FILES 1
228 // detect compilers which have support for huge stdio files
229 #if wxCHECK_VISUALC_VERSION(8)
230 #define wxHAS_HUGE_STDIO_FILES
231 #define wxFseek _fseeki64
232 #define wxFtell _ftelli64
233 #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
234 #define wxHAS_HUGE_STDIO_FILES
235 #define wxFseek fseeko64
236 #define wxFtell ftello64
239 // other Windows compilers (DMC, Watcom, Metrowerks and Borland) don't have
240 // huge file support (or at least not all functions needed for it by wx)
245 #ifdef wxHAS_HUGE_FILES
246 typedef wxLongLong_t wxFileOffset
;
247 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
249 typedef off_t wxFileOffset
;
252 // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
253 // resolution operator present in wxPOSIX_IDENT for it
255 #define wxPOSIX_STRUCT(s) struct s
257 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
260 // Notice that Watcom is the only compiler to have a wide char
261 // version of struct stat as well as a wide char stat function variant.
262 // This was dropped since OW 1.4 "for consistency across platforms".
264 // Borland is also special in that it uses _stat with Unicode functions
265 // (for MSVC compatibility?) but stat with ANSI ones
268 #define wxStructStat struct stati64
271 #define wxStructStat struct _stat
273 #define wxStructStat struct stat
276 #else // !__BORLANDC__
277 #ifdef wxHAS_HUGE_FILES
278 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
279 #define wxStructStat struct _wstati64
281 #define wxStructStat struct _stati64
284 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
285 #define wxStructStat struct _wstat
287 #define wxStructStat struct _stat
290 #endif // __BORLANDC__/!__BORLANDC__
295 // MSVC and compatible compilers prepend underscores to the POSIX function
296 // names, other compilers don't and even if their later versions usually do
297 // define the versions with underscores for MSVC compatibility, it's better
298 // to avoid using them as they're not present in earlier versions and
299 // always using the native functions spelling is easier than testing for
301 #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64__)
302 #define wxPOSIX_IDENT(func) ::func
303 #else // by default assume MSVC-compatible names
304 #define wxPOSIX_IDENT(func) _ ## func
305 #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
308 // first functions not working with strings, i.e. without ANSI/Unicode
310 #define wxClose wxPOSIX_IDENT(close)
312 #if defined(__MWERKS__)
313 #if __MSL__ >= 0x6000
314 #define wxRead(fd, buf, nCount) _read(fd, (void *)buf, nCount)
315 #define wxWrite(fd, buf, nCount) _write(fd, (void *)buf, nCount)
317 #define wxRead(fd, buf, nCount)\
318 _read(fd, (const char *)buf, nCount)
319 #define wxWrite(fd, buf, nCount)\
320 _write(fd, (const char *)buf, nCount)
323 #define wxRead wxPOSIX_IDENT(read)
324 #define wxWrite wxPOSIX_IDENT(write)
327 #ifdef wxHAS_HUGE_FILES
329 #define wxSeek wxPOSIX_IDENT(lseeki64)
330 #define wxLseek wxPOSIX_IDENT(lseeki64)
331 #define wxTell wxPOSIX_IDENT(telli64)
333 // unfortunately, mingw-W64 is somewhat inconsistent...
334 #define wxSeek _lseeki64
335 #define wxLseek _lseeki64
336 #define wxTell _telli64
338 #else // !wxHAS_HUGE_FILES
339 #define wxSeek wxPOSIX_IDENT(lseek)
340 #define wxLseek wxPOSIX_IDENT(lseek)
341 #define wxTell wxPOSIX_IDENT(tell)
342 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
345 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
346 // NB: this one is not POSIX and always has the underscore
347 #define wxFsync _commit
349 // could be already defined by configure (Cygwin)
356 #define wxEof wxPOSIX_IDENT(eof)
358 // then the functions taking strings
360 // first the ANSI versions
361 #define wxCRT_OpenA wxPOSIX_IDENT(open)
362 #define wxCRT_AccessA wxPOSIX_IDENT(access)
363 #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
364 #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
365 #ifdef wxHAS_HUGE_FILES
366 // MinGW-64 provides underscore-less versions of all file functions
367 // except for this one.
369 #define wxCRT_StatA _stati64
371 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
374 // Unfortunately Watcom is not consistent
375 #if defined(__OS2__) && defined(__WATCOMC__)
376 #define wxCRT_StatA _stat
378 #define wxCRT_StatA wxPOSIX_IDENT(stat)
382 // then wide char ones
384 // special workaround for buggy wopen() in bcc 5.5
385 #if defined(__BORLANDC__) && \
386 (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
387 WXDLLIMPEXP_BASE
int wxCRT_OpenW(const wxChar
*pathname
,
388 int flags
, mode_t mode
);
390 #define wxCRT_OpenW _wopen
393 #define wxCRT_AccessW _waccess
394 #define wxCRT_MkDirW _wmkdir
395 #define wxCRT_RmDirW _wrmdir
396 #ifdef wxHAS_HUGE_FILES
397 #define wxCRT_StatW _wstati64
399 #define wxCRT_StatW _wstat
401 #endif // wxUSE_UNICODE
404 // finally the default char-type versions
406 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
407 // implement the missing file functions in Win9x ourselves
408 WXDLLIMPEXP_BASE
int wxMSLU__wopen(const wxChar
*name
,
409 int flags
, int mode
);
410 WXDLLIMPEXP_BASE
int wxMSLU__waccess(const wxChar
*name
,
412 WXDLLIMPEXP_BASE
int wxMSLU__wmkdir(const wxChar
*name
);
413 WXDLLIMPEXP_BASE
int wxMSLU__wrmdir(const wxChar
*name
);
416 wxMSLU__wstat(const wxChar
*name
, wxStructStat
*buffer
);
418 #define wxCRT_Open wxMSLU__wopen
420 #define wxCRT_Access wxMSLU__waccess
421 #define wxCRT_MkDir wxMSLU__wmkdir
422 #define wxCRT_RmDir wxMSLU__wrmdir
423 #define wxCRT_Stat wxMSLU__wstat
424 #else // !wxUSE_UNICODE_MSLU
425 #define wxCRT_Open wxCRT_OpenW
426 #define wxCRT_Access wxCRT_AccessW
427 #define wxCRT_MkDir wxCRT_MkDirW
428 #define wxCRT_RmDir wxCRT_RmDirW
429 #define wxCRT_Stat wxCRT_StatW
430 #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
431 #else // !wxUSE_UNICODE
432 #define wxCRT_Open wxCRT_OpenA
433 #define wxCRT_Access wxCRT_AccessA
434 #define wxCRT_MkDir wxCRT_MkDirA
435 #define wxCRT_RmDir wxCRT_RmDirA
436 #define wxCRT_Stat wxCRT_StatA
437 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
440 // constants (unless already defined by the user code)
441 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
443 #define O_RDONLY _O_RDONLY
444 #define O_WRONLY _O_WRONLY
445 #define O_RDWR _O_RDWR
446 #define O_EXCL _O_EXCL
447 #define O_CREAT _O_CREAT
448 #define O_BINARY _O_BINARY
452 #define S_IFMT _S_IFMT
453 #define S_IFDIR _S_IFDIR
454 #define S_IFREG _S_IFREG
456 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
458 #ifdef wxHAS_HUGE_FILES
459 // wxFile is present and supports large files.
461 #define wxHAS_LARGE_FILES
463 // wxFFile is present and supports large files
464 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
465 #define wxHAS_LARGE_FFILES
469 // private defines, undefine so that nobody gets tempted to use
470 #undef wxHAS_HUGE_FILES
471 #undef wxHAS_HUGE_STDIO_FILES
472 #else // Unix or Windows using unknown compiler, assume POSIX supported
473 typedef off_t wxFileOffset
;
474 #ifdef HAVE_LARGEFILE_SUPPORT
475 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
476 wxCOMPILE_TIME_ASSERT( sizeof(off_t
) == sizeof(wxLongLong_t
),
478 // wxFile is present and supports large files
480 #define wxHAS_LARGE_FILES
482 // wxFFile is present and supports large files
483 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
484 #define wxHAS_LARGE_FFILES
487 #define wxFseek fseeko
488 #define wxFtell ftello
491 #define wxFileOffsetFmtSpec wxT("")
494 #define wxClose close
495 #define wxRead ::read
496 #define wxWrite ::write
497 #define wxLseek lseek
499 #define wxFsync fsync
502 #define wxCRT_MkDir mkdir
503 #define wxCRT_RmDir rmdir
505 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
507 #define wxStructStat struct stat
509 #define wxCRT_Open open
510 #define wxCRT_Stat stat
511 #define wxCRT_Lstat lstat
512 #define wxCRT_Access access
514 #define wxHAS_NATIVE_LSTAT
517 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
518 // wxCRT_Stat to avoid #ifdefs in the code using it
519 #ifndef wxHAS_NATIVE_LSTAT
520 #define wxCRT_Lstat wxCRT_Stat
523 // define wxFseek/wxFtell to large file versions if available (done above) or
524 // to fseek/ftell if not, to save ifdefs in using code
526 #define wxFseek fseek
529 #define wxFtell ftell
532 inline int wxAccess(const wxString
& path
, mode_t mode
)
533 { return wxCRT_Access(path
.fn_str(), mode
); }
534 inline int wxOpen(const wxString
& path
, int flags
, mode_t mode
)
535 { return wxCRT_Open(path
.fn_str(), flags
, mode
); }
537 // FIXME-CE: provide our own implementations of the missing CRT functions
539 inline int wxStat(const wxString
& path
, wxStructStat
*buf
)
540 { return wxCRT_Stat(path
.fn_str(), buf
); }
541 inline int wxLstat(const wxString
& path
, wxStructStat
*buf
)
542 { return wxCRT_Lstat(path
.fn_str(), buf
); }
543 inline int wxRmDir(const wxString
& path
)
544 { return wxCRT_RmDir(path
.fn_str()); }
545 #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
546 || (defined(__OS2__) && defined(__WATCOMC__))
547 inline int wxMkDir(const wxString
& path
, mode_t
WXUNUSED(mode
) = 0)
548 { return wxCRT_MkDir(path
.fn_str()); }
550 inline int wxMkDir(const wxString
& path
, mode_t mode
)
551 { return wxCRT_MkDir(path
.fn_str(), mode
); }
553 #endif // !__WXWINCE__
556 #define wxO_BINARY O_BINARY
561 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
563 // VisualAge C++ V4.0 cannot have any external linkage const decs
564 // in headers included by more than one primary source
566 extern const int wxInvalidOffset
;
568 const int wxInvalidOffset
= -1;
571 // ----------------------------------------------------------------------------
573 // ----------------------------------------------------------------------------
574 WXDLLIMPEXP_BASE
bool wxFileExists(const wxString
& filename
);
576 // does the path exist? (may have or not '/' or '\\' at the end)
577 WXDLLIMPEXP_BASE
bool wxDirExists(const wxString
& pathName
);
579 WXDLLIMPEXP_BASE
bool wxIsAbsolutePath(const wxString
& filename
);
582 WXDLLIMPEXP_BASE wxChar
* wxFileNameFromPath(wxChar
*path
);
583 WXDLLIMPEXP_BASE wxString
wxFileNameFromPath(const wxString
& path
);
586 WXDLLIMPEXP_BASE wxString
wxPathOnly(const wxString
& path
);
588 // all deprecated functions below are deprecated in favour of wxFileName's methods
589 #if WXWIN_COMPATIBILITY_2_8
591 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxDos2UnixFilename(char *s
) );
592 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxDos2UnixFilename(wchar_t *s
) );
594 wxDEPRECATED_BUT_USED_INTERNALLY(
595 WXDLLIMPEXP_BASE
void wxUnix2DosFilename(char *s
) );
596 wxDEPRECATED_BUT_USED_INTERNALLY(
597 WXDLLIMPEXP_BASE
void wxUnix2DosFilename(wchar_t *s
) );
599 // Strip the extension, in situ
600 // Deprecated in favour of wxFileName::StripExtension() but notice that their
601 // behaviour is slightly different, see the manual
602 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(char *buffer
) );
603 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(wchar_t *buffer
) );
604 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxStripExtension(wxString
& buffer
) );
606 // Get a temporary filename
607 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar
* wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
= NULL
) );
608 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
) );
610 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
611 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
char* wxExpandPath(char *dest
, const wxString
& path
) );
612 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
wchar_t* wxExpandPath(wchar_t *dest
, const wxString
& path
) );
613 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
615 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
616 // and make (if under the home tree) relative to home
617 // [caller must copy-- volatile]
619 WXDLLIMPEXP_BASE wxChar
* wxContractPath(const wxString
& filename
,
620 const wxString
& envname
= wxEmptyString
,
621 const wxString
& user
= wxEmptyString
) );
622 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
624 // Destructive removal of /./ and /../ stuff
625 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
char* wxRealPath(char *path
) );
626 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE
wchar_t* wxRealPath(wchar_t *path
) );
627 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString
wxRealPath(const wxString
& path
) );
628 // DEPRECATED: use wxFileName::Normalize instead
630 // Allocate a copy of the full absolute path
631 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar
* wxCopyAbsolutePath(const wxString
& path
) );
632 // DEPRECATED: use wxFileName::MakeAbsolute instead
635 // Get first file name matching given wild card.
636 // Flags are reserved for future use.
639 WXDLLIMPEXP_BASE wxString
wxFindFirstFile(const wxString
& spec
, int flags
= wxFILE
);
640 WXDLLIMPEXP_BASE wxString
wxFindNextFile();
642 // Does the pattern contain wildcards?
643 WXDLLIMPEXP_BASE
bool wxIsWild(const wxString
& pattern
);
645 // Does the pattern match the text (usually a filename)?
646 // If dot_special is true, doesn't match * against . (eliminating
647 // `hidden' dot files)
648 WXDLLIMPEXP_BASE
bool wxMatchWild(const wxString
& pattern
, const wxString
& text
, bool dot_special
= true);
650 // Concatenate two files to form third
651 WXDLLIMPEXP_BASE
bool wxConcatFiles(const wxString
& file1
, const wxString
& file2
, const wxString
& file3
);
653 // Copy file1 to file2
654 WXDLLIMPEXP_BASE
bool wxCopyFile(const wxString
& file1
, const wxString
& file2
,
655 bool overwrite
= true);
658 WXDLLIMPEXP_BASE
bool wxRemoveFile(const wxString
& file
);
661 WXDLLIMPEXP_BASE
bool wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
= true);
663 // Get current working directory.
664 #if WXWIN_COMPATIBILITY_2_6
665 // If buf is NULL, allocates space using new, else
667 // IMPORTANT NOTE getcwd is know not to work under some releases
668 // of Win32s 1.3, according to MS release notes!
669 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar
* wxGetWorkingDirectory(wxChar
*buf
= NULL
, int sz
= 1000) );
670 // new and preferred version of wxGetWorkingDirectory
671 // NB: can't have the same name because of overloading ambiguity
672 #endif // WXWIN_COMPATIBILITY_2_6
673 WXDLLIMPEXP_BASE wxString
wxGetCwd();
675 // Set working directory
676 WXDLLIMPEXP_BASE
bool wxSetWorkingDirectory(const wxString
& d
);
679 WXDLLIMPEXP_BASE
bool wxMkdir(const wxString
& dir
, int perm
= wxS_DIR_DEFAULT
);
681 // Remove directory. Flags reserved for future use.
682 WXDLLIMPEXP_BASE
bool wxRmdir(const wxString
& dir
, int flags
= 0);
684 // Return the type of an open file
685 WXDLLIMPEXP_BASE wxFileKind
wxGetFileKind(int fd
);
686 WXDLLIMPEXP_BASE wxFileKind
wxGetFileKind(FILE *fp
);
688 #if WXWIN_COMPATIBILITY_2_6
689 // compatibility defines, don't use in new code
690 wxDEPRECATED( inline bool wxPathExists(const wxChar
*pszPathName
) );
691 inline bool wxPathExists(const wxChar
*pszPathName
)
693 return wxDirExists(pszPathName
);
695 #endif //WXWIN_COMPATIBILITY_2_6
697 // permissions; these functions work both on files and directories:
698 WXDLLIMPEXP_BASE
bool wxIsWritable(const wxString
&path
);
699 WXDLLIMPEXP_BASE
bool wxIsReadable(const wxString
&path
);
700 WXDLLIMPEXP_BASE
bool wxIsExecutable(const wxString
&path
);
702 // ----------------------------------------------------------------------------
703 // separators in file names
704 // ----------------------------------------------------------------------------
706 // between file name and extension
707 #define wxFILE_SEP_EXT wxT('.')
709 // between drive/volume name and the path
710 #define wxFILE_SEP_DSK wxT(':')
712 // between the path components
713 #define wxFILE_SEP_PATH_DOS wxT('\\')
714 #define wxFILE_SEP_PATH_UNIX wxT('/')
715 #define wxFILE_SEP_PATH_MAC wxT(':')
716 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
718 // separator in the path list (as in PATH environment variable)
719 // there is no PATH variable in Classic Mac OS so just use the
720 // semicolon (it must be different from the file name separator)
721 // NB: these are strings and not characters on purpose!
722 #define wxPATH_SEP_DOS wxT(";")
723 #define wxPATH_SEP_UNIX wxT(":")
724 #define wxPATH_SEP_MAC wxT(";")
726 // platform independent versions
727 #if defined(__UNIX__) && !defined(__OS2__)
728 // CYGWIN also uses UNIX settings
729 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
730 #define wxPATH_SEP wxPATH_SEP_UNIX
731 #elif defined(__MAC__)
732 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
733 #define wxPATH_SEP wxPATH_SEP_MAC
734 #else // Windows and OS/2
735 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
736 #define wxPATH_SEP wxPATH_SEP_DOS
737 #endif // Unix/Windows
739 // this is useful for wxString::IsSameAs(): to compare two file names use
740 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
741 #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
742 #define wxARE_FILENAMES_CASE_SENSITIVE true
743 #else // Windows, Mac OS and OS/2
744 #define wxARE_FILENAMES_CASE_SENSITIVE false
745 #endif // Unix/Windows
747 // is the char a path separator?
748 inline bool wxIsPathSeparator(wxChar c
)
750 // under DOS/Windows we should understand both Unix and DOS file separators
751 #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
752 return c
== wxFILE_SEP_PATH
;
754 return c
== wxFILE_SEP_PATH_DOS
|| c
== wxFILE_SEP_PATH_UNIX
;
758 // does the string ends with path separator?
759 WXDLLIMPEXP_BASE
bool wxEndsWithPathSeparator(const wxString
& filename
);
761 #if WXWIN_COMPATIBILITY_2_8
762 // split the full path into path (including drive for DOS), name and extension
763 // (understands both '/' and '\\')
764 // Deprecated in favour of wxFileName::SplitPath
765 wxDEPRECATED( WXDLLIMPEXP_BASE
void wxSplitPath(const wxString
& fileName
,
768 wxString
*pstrExt
) );
771 // find a file in a list of directories, returns false if not found
772 WXDLLIMPEXP_BASE
bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
);
774 // Get the OS directory if appropriate (such as the Windows directory).
775 // On non-Windows platform, probably just return the empty string.
776 WXDLLIMPEXP_BASE wxString
wxGetOSDirectory();
780 // Get file modification time
781 WXDLLIMPEXP_BASE
time_t wxFileModificationTime(const wxString
& filename
);
783 #endif // wxUSE_DATETIME
785 // Parses the wildCard, returning the number of filters.
786 // Returns 0 if none or if there's a problem,
787 // The arrays will contain an equal number of items found before the error.
788 // wildCard is in the form:
789 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
790 WXDLLIMPEXP_BASE
int wxParseCommonDialogsFilter(const wxString
& wildCard
, wxArrayString
& descriptions
, wxArrayString
& filters
);
792 // ----------------------------------------------------------------------------
794 // ----------------------------------------------------------------------------
798 // set umask to the given value in ctor and reset it to the old one in dtor
799 class WXDLLIMPEXP_BASE wxUmaskChanger
802 // change the umask to the given one if it is not -1: this allows to write
803 // the same code whether you really want to change umask or not, as is in
804 // wxFileConfig::Flush() for example
805 wxUmaskChanger(int umaskNew
)
807 m_umaskOld
= umaskNew
== -1 ? -1 : (int)umask((mode_t
)umaskNew
);
812 if ( m_umaskOld
!= -1 )
813 umask((mode_t
)m_umaskOld
);
820 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
822 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
826 #define wxCHANGE_UMASK(m)
828 #endif // __UNIX__/!__UNIX__
832 class WXDLLIMPEXP_BASE wxPathList
: public wxArrayString
836 wxPathList(const wxArrayString
&arr
)
839 // Adds all paths in environment variable
840 void AddEnvList(const wxString
& envVariable
);
842 // Adds given path to this list
843 bool Add(const wxString
& path
);
844 void Add(const wxArrayString
&paths
);
846 // Find the first full path for which the file exists
847 wxString
FindValidPath(const wxString
& filename
) const;
849 // Find the first full path for which the file exists; ensure it's an
850 // absolute path that gets returned.
851 wxString
FindAbsoluteValidPath(const wxString
& filename
) const;
853 // Given full path and filename, add path to list
854 bool EnsureFileAccessible(const wxString
& path
);
856 #if WXWIN_COMPATIBILITY_2_6
857 // Returns true if the path is in the list
858 wxDEPRECATED( bool Member(const wxString
& path
) const );
862 #endif // _WX_FILEFN_H_