]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
Remove nonsensical custom comparison code from wxDataViewIndexListModel.
[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 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _FILEFN_H_
13 #define _FILEFN_H_
14
15 #include "wx/list.h"
16 #include "wx/arrstr.h"
17
18 #ifdef __WXWINCE__
19 #include "wx/msw/wince/time.h"
20 #include "wx/msw/private.h"
21 #else
22 #include <time.h>
23 #endif
24
25 #ifdef __WXWINCE__
26 // Nothing
27 #elif !defined(__MWERKS__)
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #else
31 #ifdef __MACH__
32 #include <sys/types.h>
33 #include <utime.h>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #else
37 #include <stat.h>
38 #include <unistd.h>
39 #include <unix.h>
40 #endif
41 #endif
42
43 #ifdef __OS2__
44 // need to check for __OS2__ first since currently both
45 // __OS2__ and __UNIX__ are defined.
46 #include <process.h>
47 #include "wx/os2/private.h"
48 #ifdef __WATCOMC__
49 #include <direct.h>
50 #endif
51 #include <io.h>
52 #ifdef __EMX__
53 #include <unistd.h>
54 #endif
55 #elif defined(__UNIX__)
56 #include <unistd.h>
57 #include <dirent.h>
58 #endif
59
60 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
61 #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
62 #include <direct.h>
63 #include <dos.h>
64 #include <io.h>
65 #endif // __WINDOWS__
66 #endif // native Win compiler
67
68 #if defined(__DOS__)
69 #ifdef __WATCOMC__
70 #include <direct.h>
71 #include <dos.h>
72 #include <io.h>
73 #endif
74 #ifdef __DJGPP__
75 #include <io.h>
76 #include <unistd.h>
77 #endif
78 #endif
79
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.
83 #include <dir.h>
84 #endif
85
86 #ifndef __WXWINCE__
87 #include <fcntl.h> // O_RDONLY &c
88 #endif
89
90 // ----------------------------------------------------------------------------
91 // constants
92 // ----------------------------------------------------------------------------
93
94 #if defined(__VISUALC__) || defined(__DIGITALMARS__)
95 typedef int mode_t;
96 #endif
97
98 #ifdef __WXWINCE__
99 typedef long off_t;
100 #else
101 // define off_t
102 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
103 #include <sys/types.h>
104 #else
105 typedef long off_t;
106 #endif
107 #endif
108
109 #if (defined(__VISUALC__) && !defined(__WXWINCE__)) || ( defined(__MWERKS__) && defined( __INTEL__) )
110 typedef _off_t off_t;
111 #elif defined(__SYMANTEC__)
112 typedef long off_t;
113 #elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
114 typedef long off_t;
115 #endif
116
117 enum wxSeekMode
118 {
119 wxFromStart,
120 wxFromCurrent,
121 wxFromEnd
122 };
123
124 enum wxFileKind
125 {
126 wxFILE_KIND_UNKNOWN,
127 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
128 wxFILE_KIND_TERMINAL, // a tty
129 wxFILE_KIND_PIPE // a pipe
130 };
131
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
135 {
136 // standard Posix names for these permission flags:
137 wxS_IRUSR = 00400,
138 wxS_IWUSR = 00200,
139 wxS_IXUSR = 00100,
140
141 wxS_IRGRP = 00040,
142 wxS_IWGRP = 00020,
143 wxS_IXGRP = 00010,
144
145 wxS_IROTH = 00004,
146 wxS_IWOTH = 00002,
147 wxS_IXOTH = 00001,
148
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,
153
154 wxPOSIX_GROUP_READ = wxS_IRGRP,
155 wxPOSIX_GROUP_WRITE = wxS_IWGRP,
156 wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
157
158 wxPOSIX_OTHERS_READ = wxS_IROTH,
159 wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
160 wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
161
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),
168
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)
175 };
176
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 // ----------------------------------------------------------------------------
181
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);
197
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(__WINDOWS__) || defined(__OS2__)) && \
204 ( \
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__) \
213 )
214
215 // temporary defines just used immediately below
216 #undef wxHAS_HUGE_FILES
217 #undef wxHAS_HUGE_STDIO_FILES
218
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
226 #endif
227
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
237 #endif
238
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)
241 // currently
242
243 // types
244
245 #ifdef wxHAS_HUGE_FILES
246 typedef wxLongLong_t wxFileOffset;
247 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
248 #else
249 typedef off_t wxFileOffset;
250 #endif
251
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
254 #ifdef __BORLANDC__
255 #define wxPOSIX_STRUCT(s) struct s
256 #else
257 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
258 #endif
259
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".
263 //
264 // Borland is also special in that it uses _stat with Unicode functions
265 // (for MSVC compatibility?) but stat with ANSI ones
266 #ifdef __BORLANDC__
267 #if wxHAS_HUGE_FILES
268 #define wxStructStat struct stati64
269 #else
270 #if wxUSE_UNICODE
271 #define wxStructStat struct _stat
272 #else
273 #define wxStructStat struct stat
274 #endif
275 #endif
276 #else // !__BORLANDC__
277 #ifdef wxHAS_HUGE_FILES
278 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
279 #define wxStructStat struct _wstati64
280 #else
281 #define wxStructStat struct _stati64
282 #endif
283 #else
284 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
285 #define wxStructStat struct _wstat
286 #else
287 #define wxStructStat struct _stat
288 #endif
289 #endif
290 #endif // __BORLANDC__/!__BORLANDC__
291
292
293 // functions
294
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
300 // the versions
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
306 #endif
307
308 // first functions not working with strings, i.e. without ANSI/Unicode
309 // complications
310 #define wxClose wxPOSIX_IDENT(close)
311
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)
316 #else
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)
321 #endif
322 #else // __MWERKS__
323 #define wxRead wxPOSIX_IDENT(read)
324 #define wxWrite wxPOSIX_IDENT(write)
325 #endif
326
327 #ifdef wxHAS_HUGE_FILES
328 #ifndef __MINGW64__
329 #define wxSeek wxPOSIX_IDENT(lseeki64)
330 #define wxLseek wxPOSIX_IDENT(lseeki64)
331 #define wxTell wxPOSIX_IDENT(telli64)
332 #else
333 // unfortunately, mingw-W64 is somewhat inconsistent...
334 #define wxSeek _lseeki64
335 #define wxLseek _lseeki64
336 #define wxTell _telli64
337 #endif
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
343
344 #ifndef __WATCOMC__
345 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
346 // NB: this one is not POSIX and always has the underscore
347 #define wxFsync _commit
348
349 // could be already defined by configure (Cygwin)
350 #ifndef HAVE_FSYNC
351 #define HAVE_FSYNC
352 #endif
353 #endif // BORLANDC
354 #endif
355
356 #define wxEof wxPOSIX_IDENT(eof)
357
358 // then the functions taking strings
359
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.
368 #ifdef __MINGW64__
369 #define wxCRT_StatA _stati64
370 #else
371 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
372 #endif
373 #else
374 // Unfortunately Watcom is not consistent
375 #if defined(__OS2__) && defined(__WATCOMC__)
376 #define wxCRT_StatA _stat
377 #else
378 #define wxCRT_StatA wxPOSIX_IDENT(stat)
379 #endif
380 #endif
381
382 // then wide char ones
383 #if wxUSE_UNICODE
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);
389 #else
390 #define wxCRT_OpenW _wopen
391 #endif
392
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
398 #else
399 #define wxCRT_StatW _wstat
400 #endif
401 #endif // wxUSE_UNICODE
402
403
404 // finally the default char-type versions
405 #if wxUSE_UNICODE
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,
411 int mode);
412 WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
413 WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
414
415 WXDLLIMPEXP_BASE int
416 wxMSLU__wstat(const wxChar *name, wxStructStat *buffer);
417
418 #define wxCRT_Open wxMSLU__wopen
419
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
438
439
440 // constants (unless already defined by the user code)
441 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
442 #ifndef O_RDONLY
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
449 #endif
450
451 #ifndef S_IFMT
452 #define S_IFMT _S_IFMT
453 #define S_IFDIR _S_IFDIR
454 #define S_IFREG _S_IFREG
455 #endif
456 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
457
458 #ifdef wxHAS_HUGE_FILES
459 // wxFile is present and supports large files.
460 #if wxUSE_FILE
461 #define wxHAS_LARGE_FILES
462 #endif
463 // wxFFile is present and supports large files
464 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
465 #define wxHAS_LARGE_FFILES
466 #endif
467 #endif
468
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),
477 BadFileSizeType );
478 // wxFile is present and supports large files
479 #if wxUSE_FILE
480 #define wxHAS_LARGE_FILES
481 #endif
482 // wxFFile is present and supports large files
483 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
484 #define wxHAS_LARGE_FFILES
485 #endif
486 #ifdef HAVE_FSEEKO
487 #define wxFseek fseeko
488 #define wxFtell ftello
489 #endif
490 #else
491 #define wxFileOffsetFmtSpec wxT("")
492 #endif
493 // functions
494 #define wxClose close
495 #define wxRead ::read
496 #define wxWrite ::write
497 #define wxLseek lseek
498 #define wxSeek lseek
499 #define wxFsync fsync
500 #define wxEof eof
501
502 #define wxCRT_MkDir mkdir
503 #define wxCRT_RmDir rmdir
504
505 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
506
507 #define wxStructStat struct stat
508
509 #define wxCRT_Open open
510 #define wxCRT_Stat stat
511 #define wxCRT_Lstat lstat
512 #define wxCRT_Access access
513
514 #define wxHAS_NATIVE_LSTAT
515 #endif // platforms
516
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
521 #endif
522
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
525 #ifndef wxFseek
526 #define wxFseek fseek
527 #endif
528 #ifndef wxFtell
529 #define wxFtell ftell
530 #endif
531
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); }
536
537 // FIXME-CE: provide our own implementations of the missing CRT functions
538 #ifndef __WXWINCE__
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()); }
549 #else
550 inline int wxMkDir(const wxString& path, mode_t mode)
551 { return wxCRT_MkDir(path.fn_str(), mode); }
552 #endif
553 #endif // !__WXWINCE__
554
555 #ifdef O_BINARY
556 #define wxO_BINARY O_BINARY
557 #else
558 #define wxO_BINARY 0
559 #endif
560
561 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
562 //
563 // VisualAge C++ V4.0 cannot have any external linkage const decs
564 // in headers included by more than one primary source
565 //
566 extern const int wxInvalidOffset;
567 #else
568 const int wxInvalidOffset = -1;
569 #endif
570
571 // ----------------------------------------------------------------------------
572 // functions
573 // ----------------------------------------------------------------------------
574 WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
575
576 // does the path exist? (may have or not '/' or '\\' at the end)
577 WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
578
579 WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
580
581 // Get filename
582 WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
583 WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
584
585 // Get directory
586 WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
587
588 // all deprecated functions below are deprecated in favour of wxFileName's methods
589 #if WXWIN_COMPATIBILITY_2_8
590
591 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
592 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
593
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) );
598
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) );
605
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) );
609
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)
614
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]
618 wxDEPRECATED(
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
623
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
629
630 // Allocate a copy of the full absolute path
631 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
632 // DEPRECATED: use wxFileName::MakeAbsolute instead
633 #endif
634
635 // Get first file name matching given wild card.
636 // Flags are reserved for future use.
637 #define wxFILE 1
638 #define wxDIR 2
639 WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
640 WXDLLIMPEXP_BASE wxString wxFindNextFile();
641
642 // Does the pattern contain wildcards?
643 WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
644
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);
649
650 // Concatenate two files to form third
651 WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
652
653 // Copy file1 to file2
654 WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
655 bool overwrite = true);
656
657 // Remove file
658 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
659
660 // Rename file
661 WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
662
663 // Get current working directory.
664 #if WXWIN_COMPATIBILITY_2_6
665 // If buf is NULL, allocates space using new, else
666 // copies into buf.
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();
674
675 // Set working directory
676 WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
677
678 // Make directory
679 WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
680
681 // Remove directory. Flags reserved for future use.
682 WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
683
684 // Return the type of an open file
685 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
686 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
687
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)
692 {
693 return wxDirExists(pszPathName);
694 }
695 #endif //WXWIN_COMPATIBILITY_2_6
696
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);
701
702 // ----------------------------------------------------------------------------
703 // separators in file names
704 // ----------------------------------------------------------------------------
705
706 // between file name and extension
707 #define wxFILE_SEP_EXT wxT('.')
708
709 // between drive/volume name and the path
710 #define wxFILE_SEP_DSK wxT(':')
711
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 ']'
717
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(";")
725
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
738
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
746
747 // is the char a path separator?
748 inline bool wxIsPathSeparator(wxChar c)
749 {
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;
753 #else
754 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
755 #endif
756 }
757
758 // does the string ends with path separator?
759 WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
760
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,
766 wxString *pstrPath,
767 wxString *pstrName,
768 wxString *pstrExt) );
769 #endif
770
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);
773
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();
777
778 #if wxUSE_DATETIME
779
780 // Get file modification time
781 WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
782
783 #endif // wxUSE_DATETIME
784
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);
791
792 // ----------------------------------------------------------------------------
793 // classes
794 // ----------------------------------------------------------------------------
795
796 #ifdef __UNIX__
797
798 // set umask to the given value in ctor and reset it to the old one in dtor
799 class WXDLLIMPEXP_BASE wxUmaskChanger
800 {
801 public:
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)
806 {
807 m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
808 }
809
810 ~wxUmaskChanger()
811 {
812 if ( m_umaskOld != -1 )
813 umask((mode_t)m_umaskOld);
814 }
815
816 private:
817 int m_umaskOld;
818 };
819
820 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
821 // nothing elsewhere
822 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
823
824 #else // !__UNIX__
825
826 #define wxCHANGE_UMASK(m)
827
828 #endif // __UNIX__/!__UNIX__
829
830
831 // Path searching
832 class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
833 {
834 public:
835 wxPathList() {}
836 wxPathList(const wxArrayString &arr)
837 { Add(arr); }
838
839 // Adds all paths in environment variable
840 void AddEnvList(const wxString& envVariable);
841
842 // Adds given path to this list
843 bool Add(const wxString& path);
844 void Add(const wxArrayString &paths);
845
846 // Find the first full path for which the file exists
847 wxString FindValidPath(const wxString& filename) const;
848
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;
852
853 // Given full path and filename, add path to list
854 bool EnsureFileAccessible(const wxString& path);
855
856 #if WXWIN_COMPATIBILITY_2_6
857 // Returns true if the path is in the list
858 wxDEPRECATED( bool Member(const wxString& path) const );
859 #endif
860 };
861
862 #endif // _WX_FILEFN_H_