]> git.saurik.com Git - wxWidgets.git/blob - include/wx/filefn.h
Remove code to find topmost X window in SetTransparent().
[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 #ifndef __WXWINCE__
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #endif
29
30 #ifdef __OS2__
31 // need to check for __OS2__ first since currently both
32 // __OS2__ and __UNIX__ are defined.
33 #include <process.h>
34 #include "wx/os2/private.h"
35 #ifdef __WATCOMC__
36 #include <direct.h>
37 #endif
38 #include <io.h>
39 #ifdef __EMX__
40 #include <unistd.h>
41 #endif
42 #elif defined(__UNIX__)
43 #include <unistd.h>
44 #include <dirent.h>
45 #endif
46
47 #if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
48 #if !defined( __GNUWIN32__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
49 #include <direct.h>
50 #include <dos.h>
51 #include <io.h>
52 #endif // __WINDOWS__
53 #endif // native Win compiler
54
55 #if defined(__DOS__)
56 #ifdef __WATCOMC__
57 #include <direct.h>
58 #include <dos.h>
59 #include <io.h>
60 #endif
61 #ifdef __DJGPP__
62 #include <io.h>
63 #include <unistd.h>
64 #endif
65 #endif
66
67 #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
68 // this (3.1 I believe) and how to test for it.
69 // If this works for Borland 4.0 as well, then no worries.
70 #include <dir.h>
71 #endif
72
73 #ifndef __WXWINCE__
74 #include <fcntl.h> // O_RDONLY &c
75 #endif
76
77 // ----------------------------------------------------------------------------
78 // constants
79 // ----------------------------------------------------------------------------
80
81 #if defined(__VISUALC__) || defined(__DIGITALMARS__)
82 typedef int mode_t;
83 #endif
84
85 #ifdef __WXWINCE__
86 typedef long off_t;
87 #else
88 // define off_t
89 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
90 #include <sys/types.h>
91 #else
92 typedef long off_t;
93 #endif
94 #endif
95
96 #if defined(__VISUALC__) && !defined(__WXWINCE__)
97 typedef _off_t off_t;
98 #elif defined(__SYMANTEC__)
99 typedef long off_t;
100 #endif
101
102 enum wxSeekMode
103 {
104 wxFromStart,
105 wxFromCurrent,
106 wxFromEnd
107 };
108
109 enum wxFileKind
110 {
111 wxFILE_KIND_UNKNOWN,
112 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
113 wxFILE_KIND_TERMINAL, // a tty
114 wxFILE_KIND_PIPE // a pipe
115 };
116
117 // we redefine these constants here because S_IREAD &c are _not_ standard
118 // however, we do assume that the values correspond to the Unix umask bits
119 enum wxPosixPermissions
120 {
121 // standard Posix names for these permission flags:
122 wxS_IRUSR = 00400,
123 wxS_IWUSR = 00200,
124 wxS_IXUSR = 00100,
125
126 wxS_IRGRP = 00040,
127 wxS_IWGRP = 00020,
128 wxS_IXGRP = 00010,
129
130 wxS_IROTH = 00004,
131 wxS_IWOTH = 00002,
132 wxS_IXOTH = 00001,
133
134 // longer but more readable synonyms for the constants above:
135 wxPOSIX_USER_READ = wxS_IRUSR,
136 wxPOSIX_USER_WRITE = wxS_IWUSR,
137 wxPOSIX_USER_EXECUTE = wxS_IXUSR,
138
139 wxPOSIX_GROUP_READ = wxS_IRGRP,
140 wxPOSIX_GROUP_WRITE = wxS_IWGRP,
141 wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
142
143 wxPOSIX_OTHERS_READ = wxS_IROTH,
144 wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
145 wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
146
147 // default mode for the new files: allow reading/writing them to everybody but
148 // the effective file mode will be set after anding this value with umask and
149 // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
150 wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
151 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
152 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
153
154 // default mode for the new directories (see wxFileName::Mkdir): allow
155 // reading/writing/executing them to everybody, but just like wxS_DEFAULT
156 // the effective directory mode will be set after anding this value with umask
157 wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
158 wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
159 wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
160 };
161
162 // ----------------------------------------------------------------------------
163 // declare our versions of low level file functions: some compilers prepend
164 // underscores to the usual names, some also have Unicode versions of them
165 // ----------------------------------------------------------------------------
166
167 // Wrappers around Win32 api functions like CreateFile, ReadFile and such
168 // Implemented in filefnwce.cpp
169 #if defined( __WXWINCE__)
170 typedef __int64 wxFileOffset;
171 #define wxFileOffsetFmtSpec wxT("I64")
172 WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode));
173 WXDLLIMPEXP_BASE int wxCRT_Access(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);
182
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__)) && \
189 ( \
190 defined(__VISUALC__) || \
191 defined(__MINGW64__) || \
192 (defined(__MINGW32__) && !defined(__WINE__) && \
193 wxCHECK_W32API_VERSION(0, 5)) || \
194 defined(__DMC__) || \
195 defined(__WATCOMC__) || \
196 defined(__BORLANDC__) \
197 )
198
199 // temporary defines just used immediately below
200 #undef wxHAS_HUGE_FILES
201 #undef wxHAS_HUGE_STDIO_FILES
202
203 // detect compilers which have support for huge files
204 #if defined(__VISUALC__)
205 #define wxHAS_HUGE_FILES 1
206 #elif defined(__MINGW32__) || defined(__MINGW64__)
207 #define wxHAS_HUGE_FILES 1
208 #elif defined(_LARGE_FILES)
209 #define wxHAS_HUGE_FILES 1
210 #endif
211
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
221 #endif
222
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
225
226 // types
227
228 #ifdef wxHAS_HUGE_FILES
229 typedef wxLongLong_t wxFileOffset;
230 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
231 #else
232 typedef off_t wxFileOffset;
233 #endif
234
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
237 #ifdef __BORLANDC__
238 #define wxPOSIX_STRUCT(s) struct s
239 #else
240 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
241 #endif
242
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".
246 //
247 // Borland is also special in that it uses _stat with Unicode functions
248 // (for MSVC compatibility?) but stat with ANSI ones
249 #ifdef __BORLANDC__
250 #if wxHAS_HUGE_FILES
251 #define wxStructStat struct stati64
252 #else
253 #if wxUSE_UNICODE
254 #define wxStructStat struct _stat
255 #else
256 #define wxStructStat struct stat
257 #endif
258 #endif
259 #else // !__BORLANDC__
260 #ifdef wxHAS_HUGE_FILES
261 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
262 #define wxStructStat struct _wstati64
263 #else
264 #define wxStructStat struct _stati64
265 #endif
266 #else
267 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
268 #define wxStructStat struct _wstat
269 #else
270 #define wxStructStat struct _stat
271 #endif
272 #endif
273 #endif // __BORLANDC__/!__BORLANDC__
274
275
276 // functions
277
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
283 // the versions
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
289 #endif
290
291 // first functions not working with strings, i.e. without ANSI/Unicode
292 // complications
293 #define wxClose wxPOSIX_IDENT(close)
294
295 #define wxRead wxPOSIX_IDENT(read)
296 #define wxWrite wxPOSIX_IDENT(write)
297
298 #ifdef wxHAS_HUGE_FILES
299 #ifndef __MINGW64__
300 #define wxSeek wxPOSIX_IDENT(lseeki64)
301 #define wxLseek wxPOSIX_IDENT(lseeki64)
302 #define wxTell wxPOSIX_IDENT(telli64)
303 #else
304 // unfortunately, mingw-W64 is somewhat inconsistent...
305 #define wxSeek _lseeki64
306 #define wxLseek _lseeki64
307 #define wxTell _telli64
308 #endif
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
314
315 #ifndef __WATCOMC__
316 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
317 // NB: this one is not POSIX and always has the underscore
318 #define wxFsync _commit
319
320 // could be already defined by configure (Cygwin)
321 #ifndef HAVE_FSYNC
322 #define HAVE_FSYNC
323 #endif
324 #endif // BORLANDC
325 #endif
326
327 #define wxEof wxPOSIX_IDENT(eof)
328
329 // then the functions taking strings
330
331 // first the ANSI versions
332 #define wxCRT_OpenA wxPOSIX_IDENT(open)
333 #define wxCRT_AccessA wxPOSIX_IDENT(access)
334 #define wxCRT_MkDirA wxPOSIX_IDENT(mkdir)
335 #define wxCRT_RmDirA wxPOSIX_IDENT(rmdir)
336 #ifdef wxHAS_HUGE_FILES
337 // MinGW-64 provides underscore-less versions of all file functions
338 // except for this one.
339 #ifdef __MINGW64__
340 #define wxCRT_StatA _stati64
341 #else
342 #define wxCRT_StatA wxPOSIX_IDENT(stati64)
343 #endif
344 #else
345 // Unfortunately Watcom is not consistent
346 #if defined(__OS2__) && defined(__WATCOMC__)
347 #define wxCRT_StatA _stat
348 #else
349 #define wxCRT_StatA wxPOSIX_IDENT(stat)
350 #endif
351 #endif
352
353 // then wide char ones
354 #if wxUSE_UNICODE
355 // special workaround for buggy wopen() in bcc 5.5
356 #if defined(__BORLANDC__) && \
357 (__BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551)
358 WXDLLIMPEXP_BASE int wxCRT_OpenW(const wxChar *pathname,
359 int flags, mode_t mode);
360 #else
361 #define wxCRT_OpenW _wopen
362 #endif
363
364 #define wxCRT_AccessW _waccess
365 #define wxCRT_MkDirW _wmkdir
366 #define wxCRT_RmDirW _wrmdir
367 #ifdef wxHAS_HUGE_FILES
368 #define wxCRT_StatW _wstati64
369 #else
370 #define wxCRT_StatW _wstat
371 #endif
372 #endif // wxUSE_UNICODE
373
374
375 // finally the default char-type versions
376 #if wxUSE_UNICODE
377 #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
378 // implement the missing file functions in Win9x ourselves
379 WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name,
380 int flags, int mode);
381 WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name,
382 int mode);
383 WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
384 WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
385
386 WXDLLIMPEXP_BASE int
387 wxMSLU__wstat(const wxChar *name, wxStructStat *buffer);
388
389 #define wxCRT_Open wxMSLU__wopen
390
391 #define wxCRT_Access wxMSLU__waccess
392 #define wxCRT_MkDir wxMSLU__wmkdir
393 #define wxCRT_RmDir wxMSLU__wrmdir
394 #define wxCRT_Stat wxMSLU__wstat
395 #else // !wxUSE_UNICODE_MSLU
396 #define wxCRT_Open wxCRT_OpenW
397 #define wxCRT_Access wxCRT_AccessW
398 #define wxCRT_MkDir wxCRT_MkDirW
399 #define wxCRT_RmDir wxCRT_RmDirW
400 #define wxCRT_Stat wxCRT_StatW
401 #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
402 #else // !wxUSE_UNICODE
403 #define wxCRT_Open wxCRT_OpenA
404 #define wxCRT_Access wxCRT_AccessA
405 #define wxCRT_MkDir wxCRT_MkDirA
406 #define wxCRT_RmDir wxCRT_RmDirA
407 #define wxCRT_Stat wxCRT_StatA
408 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
409
410
411 // constants (unless already defined by the user code)
412 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
413 #ifndef O_RDONLY
414 #define O_RDONLY _O_RDONLY
415 #define O_WRONLY _O_WRONLY
416 #define O_RDWR _O_RDWR
417 #define O_EXCL _O_EXCL
418 #define O_CREAT _O_CREAT
419 #define O_BINARY _O_BINARY
420 #endif
421
422 #ifndef S_IFMT
423 #define S_IFMT _S_IFMT
424 #define S_IFDIR _S_IFDIR
425 #define S_IFREG _S_IFREG
426 #endif
427 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
428
429 #ifdef wxHAS_HUGE_FILES
430 // wxFile is present and supports large files.
431 #if wxUSE_FILE
432 #define wxHAS_LARGE_FILES
433 #endif
434 // wxFFile is present and supports large files
435 #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
436 #define wxHAS_LARGE_FFILES
437 #endif
438 #endif
439
440 // private defines, undefine so that nobody gets tempted to use
441 #undef wxHAS_HUGE_FILES
442 #undef wxHAS_HUGE_STDIO_FILES
443 #else // Unix or Windows using unknown compiler, assume POSIX supported
444 typedef off_t wxFileOffset;
445 #ifdef HAVE_LARGEFILE_SUPPORT
446 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
447 wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
448 BadFileSizeType );
449 // wxFile is present and supports large files
450 #if wxUSE_FILE
451 #define wxHAS_LARGE_FILES
452 #endif
453 // wxFFile is present and supports large files
454 #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
455 #define wxHAS_LARGE_FFILES
456 #endif
457 #ifdef HAVE_FSEEKO
458 #define wxFseek fseeko
459 #define wxFtell ftello
460 #endif
461 #else
462 #define wxFileOffsetFmtSpec wxT("")
463 #endif
464 // functions
465 #define wxClose close
466 #define wxRead ::read
467 #define wxWrite ::write
468 #define wxLseek lseek
469 #define wxSeek lseek
470 #define wxFsync fsync
471 #define wxEof eof
472
473 #define wxCRT_MkDir mkdir
474 #define wxCRT_RmDir rmdir
475
476 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
477
478 #define wxStructStat struct stat
479
480 #define wxCRT_Open open
481 #define wxCRT_Stat stat
482 #define wxCRT_Lstat lstat
483 #define wxCRT_Access access
484
485 #define wxHAS_NATIVE_LSTAT
486 #endif // platforms
487
488 // if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
489 // wxCRT_Stat to avoid #ifdefs in the code using it
490 #ifndef wxHAS_NATIVE_LSTAT
491 #define wxCRT_Lstat wxCRT_Stat
492 #endif
493
494 // define wxFseek/wxFtell to large file versions if available (done above) or
495 // to fseek/ftell if not, to save ifdefs in using code
496 #ifndef wxFseek
497 #define wxFseek fseek
498 #endif
499 #ifndef wxFtell
500 #define wxFtell ftell
501 #endif
502
503 inline int wxAccess(const wxString& path, mode_t mode)
504 { return wxCRT_Access(path.fn_str(), mode); }
505 inline int wxOpen(const wxString& path, int flags, mode_t mode)
506 { return wxCRT_Open(path.fn_str(), flags, mode); }
507
508 // FIXME-CE: provide our own implementations of the missing CRT functions
509 #ifndef __WXWINCE__
510 inline int wxStat(const wxString& path, wxStructStat *buf)
511 { return wxCRT_Stat(path.fn_str(), buf); }
512 inline int wxLstat(const wxString& path, wxStructStat *buf)
513 { return wxCRT_Lstat(path.fn_str(), buf); }
514 inline int wxRmDir(const wxString& path)
515 { return wxCRT_RmDir(path.fn_str()); }
516 #if (defined(__WINDOWS__) && !defined(__CYGWIN__)) \
517 || (defined(__OS2__) && defined(__WATCOMC__))
518 inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
519 { return wxCRT_MkDir(path.fn_str()); }
520 #else
521 inline int wxMkDir(const wxString& path, mode_t mode)
522 { return wxCRT_MkDir(path.fn_str(), mode); }
523 #endif
524 #endif // !__WXWINCE__
525
526 #ifdef O_BINARY
527 #define wxO_BINARY O_BINARY
528 #else
529 #define wxO_BINARY 0
530 #endif
531
532 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
533 //
534 // VisualAge C++ V4.0 cannot have any external linkage const decs
535 // in headers included by more than one primary source
536 //
537 extern const int wxInvalidOffset;
538 #else
539 const int wxInvalidOffset = -1;
540 #endif
541
542 // ----------------------------------------------------------------------------
543 // functions
544 // ----------------------------------------------------------------------------
545 WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
546
547 // does the path exist? (may have or not '/' or '\\' at the end)
548 WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
549
550 WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
551
552 // Get filename
553 WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
554 WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
555
556 // Get directory
557 WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
558
559 // all deprecated functions below are deprecated in favour of wxFileName's methods
560 #if WXWIN_COMPATIBILITY_2_8
561
562 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
563 wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
564
565 wxDEPRECATED_BUT_USED_INTERNALLY(
566 WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
567 wxDEPRECATED_BUT_USED_INTERNALLY(
568 WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
569
570 // Strip the extension, in situ
571 // Deprecated in favour of wxFileName::StripExtension() but notice that their
572 // behaviour is slightly different, see the manual
573 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
574 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
575 wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
576
577 // Get a temporary filename
578 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
579 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
580
581 // Expand file name (~/ and ${OPENWINHOME}/ stuff)
582 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
583 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
584 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
585
586 // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
587 // and make (if under the home tree) relative to home
588 // [caller must copy-- volatile]
589 wxDEPRECATED(
590 WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
591 const wxString& envname = wxEmptyString,
592 const wxString& user = wxEmptyString) );
593 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
594
595 // Destructive removal of /./ and /../ stuff
596 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
597 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
598 wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
599 // DEPRECATED: use wxFileName::Normalize instead
600
601 // Allocate a copy of the full absolute path
602 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
603 // DEPRECATED: use wxFileName::MakeAbsolute instead
604 #endif
605
606 // Get first file name matching given wild card.
607 // Flags are reserved for future use.
608 #define wxFILE 1
609 #define wxDIR 2
610 WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
611 WXDLLIMPEXP_BASE wxString wxFindNextFile();
612
613 // Does the pattern contain wildcards?
614 WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
615
616 // Does the pattern match the text (usually a filename)?
617 // If dot_special is true, doesn't match * against . (eliminating
618 // `hidden' dot files)
619 WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
620
621 // Concatenate two files to form third
622 WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
623
624 // Copy file1 to file2
625 WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
626 bool overwrite = true);
627
628 // Remove file
629 WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
630
631 // Rename file
632 WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
633
634 // Get current working directory.
635 #if WXWIN_COMPATIBILITY_2_6
636 // If buf is NULL, allocates space using new, else
637 // copies into buf.
638 // IMPORTANT NOTE getcwd is know not to work under some releases
639 // of Win32s 1.3, according to MS release notes!
640 wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = NULL, int sz = 1000) );
641 // new and preferred version of wxGetWorkingDirectory
642 // NB: can't have the same name because of overloading ambiguity
643 #endif // WXWIN_COMPATIBILITY_2_6
644 WXDLLIMPEXP_BASE wxString wxGetCwd();
645
646 // Set working directory
647 WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
648
649 // Make directory
650 WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
651
652 // Remove directory. Flags reserved for future use.
653 WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
654
655 // Return the type of an open file
656 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
657 WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
658
659 #if WXWIN_COMPATIBILITY_2_6
660 // compatibility defines, don't use in new code
661 wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
662 inline bool wxPathExists(const wxChar *pszPathName)
663 {
664 return wxDirExists(pszPathName);
665 }
666 #endif //WXWIN_COMPATIBILITY_2_6
667
668 // permissions; these functions work both on files and directories:
669 WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
670 WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
671 WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
672
673 // ----------------------------------------------------------------------------
674 // separators in file names
675 // ----------------------------------------------------------------------------
676
677 // between file name and extension
678 #define wxFILE_SEP_EXT wxT('.')
679
680 // between drive/volume name and the path
681 #define wxFILE_SEP_DSK wxT(':')
682
683 // between the path components
684 #define wxFILE_SEP_PATH_DOS wxT('\\')
685 #define wxFILE_SEP_PATH_UNIX wxT('/')
686 #define wxFILE_SEP_PATH_MAC wxT(':')
687 #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
688
689 // separator in the path list (as in PATH environment variable)
690 // there is no PATH variable in Classic Mac OS so just use the
691 // semicolon (it must be different from the file name separator)
692 // NB: these are strings and not characters on purpose!
693 #define wxPATH_SEP_DOS wxT(";")
694 #define wxPATH_SEP_UNIX wxT(":")
695 #define wxPATH_SEP_MAC wxT(";")
696
697 // platform independent versions
698 #if defined(__UNIX__) && !defined(__OS2__)
699 // CYGWIN also uses UNIX settings
700 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
701 #define wxPATH_SEP wxPATH_SEP_UNIX
702 #elif defined(__MAC__)
703 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
704 #define wxPATH_SEP wxPATH_SEP_MAC
705 #else // Windows and OS/2
706 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
707 #define wxPATH_SEP wxPATH_SEP_DOS
708 #endif // Unix/Windows
709
710 // this is useful for wxString::IsSameAs(): to compare two file names use
711 // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
712 #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
713 #define wxARE_FILENAMES_CASE_SENSITIVE true
714 #else // Windows, Mac OS and OS/2
715 #define wxARE_FILENAMES_CASE_SENSITIVE false
716 #endif // Unix/Windows
717
718 // is the char a path separator?
719 inline bool wxIsPathSeparator(wxChar c)
720 {
721 // under DOS/Windows we should understand both Unix and DOS file separators
722 #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
723 return c == wxFILE_SEP_PATH;
724 #else
725 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
726 #endif
727 }
728
729 // does the string ends with path separator?
730 WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
731
732 #if WXWIN_COMPATIBILITY_2_8
733 // split the full path into path (including drive for DOS), name and extension
734 // (understands both '/' and '\\')
735 // Deprecated in favour of wxFileName::SplitPath
736 wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
737 wxString *pstrPath,
738 wxString *pstrName,
739 wxString *pstrExt) );
740 #endif
741
742 // find a file in a list of directories, returns false if not found
743 WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
744
745 // Get the OS directory if appropriate (such as the Windows directory).
746 // On non-Windows platform, probably just return the empty string.
747 WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
748
749 #if wxUSE_DATETIME
750
751 // Get file modification time
752 WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
753
754 #endif // wxUSE_DATETIME
755
756 // Parses the wildCard, returning the number of filters.
757 // Returns 0 if none or if there's a problem,
758 // The arrays will contain an equal number of items found before the error.
759 // wildCard is in the form:
760 // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
761 WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
762
763 // ----------------------------------------------------------------------------
764 // classes
765 // ----------------------------------------------------------------------------
766
767 #ifdef __UNIX__
768
769 // set umask to the given value in ctor and reset it to the old one in dtor
770 class WXDLLIMPEXP_BASE wxUmaskChanger
771 {
772 public:
773 // change the umask to the given one if it is not -1: this allows to write
774 // the same code whether you really want to change umask or not, as is in
775 // wxFileConfig::Flush() for example
776 wxUmaskChanger(int umaskNew)
777 {
778 m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
779 }
780
781 ~wxUmaskChanger()
782 {
783 if ( m_umaskOld != -1 )
784 umask((mode_t)m_umaskOld);
785 }
786
787 private:
788 int m_umaskOld;
789 };
790
791 // this macro expands to an "anonymous" wxUmaskChanger object under Unix and
792 // nothing elsewhere
793 #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
794
795 #else // !__UNIX__
796
797 #define wxCHANGE_UMASK(m)
798
799 #endif // __UNIX__/!__UNIX__
800
801
802 // Path searching
803 class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
804 {
805 public:
806 wxPathList() {}
807 wxPathList(const wxArrayString &arr)
808 { Add(arr); }
809
810 // Adds all paths in environment variable
811 void AddEnvList(const wxString& envVariable);
812
813 // Adds given path to this list
814 bool Add(const wxString& path);
815 void Add(const wxArrayString &paths);
816
817 // Find the first full path for which the file exists
818 wxString FindValidPath(const wxString& filename) const;
819
820 // Find the first full path for which the file exists; ensure it's an
821 // absolute path that gets returned.
822 wxString FindAbsoluteValidPath(const wxString& filename) const;
823
824 // Given full path and filename, add path to list
825 bool EnsureFileAccessible(const wxString& path);
826
827 #if WXWIN_COMPATIBILITY_2_6
828 // Returns true if the path is in the list
829 wxDEPRECATED( bool Member(const wxString& path) const );
830 #endif
831 };
832
833 #endif // _WX_FILEFN_H_