]> git.saurik.com Git - wxWidgets.git/blame - include/wx/filefn.h
this one should really work
[wxWidgets.git] / include / wx / filefn.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
55034339 2// Name: wx/filefn.h
c801d85f
KB
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
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _FILEFN_H_
13#define _FILEFN_H_
c801d85f 14
ed58dbea 15#include "wx/list.h"
b76069e2 16#include "wx/arrstr.h"
e49f47aa 17
e2fc40b4 18#ifndef __WXPALMOS5__
6294ac2e
VZ
19#ifdef __WXWINCE__
20 #include "wx/msw/wince/time.h"
21 #include "wx/msw/private.h"
22#else
23 #include <time.h>
0e0126c2 24#endif
a47ce4a7 25
6294ac2e
VZ
26#ifdef __WXWINCE__
27// Nothing
28#elif !defined(__MWERKS__)
29 #include <sys/types.h>
30 #include <sys/stat.h>
31#else
32 #ifdef __MACH__
33 #include <sys/types.h>
34 #include <utime.h>
35 #include <sys/stat.h>
36 #include <unistd.h>
37 #else
38 #include <stat.h>
39 #include <unistd.h>
40 #include <unix.h>
41 #endif
42#endif
e2fc40b4 43#endif // !__WXPALMOS5__
6294ac2e
VZ
44
45#ifdef __OS2__
46// need to check for __OS2__ first since currently both
47// __OS2__ and __UNIX__ are defined.
48 #include <process.h>
49 #include "wx/os2/private.h"
0872eaf9
WS
50 #ifdef __WATCOMC__
51 #include <direct.h>
52 #endif
6294ac2e
VZ
53 #include <io.h>
54 #ifdef __EMX__
55 #include <unistd.h>
56 #endif
57#elif defined(__UNIX__)
58 #include <unistd.h>
59 #include <dirent.h>
60#endif
61
62#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
f172cb82 63#if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__WXWINCE__) && !defined(__CYGWIN__)
6294ac2e
VZ
64 #include <direct.h>
65 #include <dos.h>
66 #include <io.h>
67#endif // __WINDOWS__
68#endif // native Win compiler
69
70#if defined(__DOS__)
71 #ifdef __WATCOMC__
72 #include <direct.h>
73 #include <dos.h>
74 #include <io.h>
75 #endif
76 #ifdef __DJGPP__
77 #include <io.h>
78 #include <unistd.h>
79 #endif
80#endif
81
82#ifdef __BORLANDC__ // Please someone tell me which version of Borland needs
83 // this (3.1 I believe) and how to test for it.
84 // If this works for Borland 4.0 as well, then no worries.
85 #include <dir.h>
86#endif
87
e2fc40b4 88#ifndef __WXPALMOS5__
6294ac2e
VZ
89#ifndef __WXWINCE__
90 #include <fcntl.h> // O_RDONLY &c
91#endif
e2fc40b4 92#endif // !__WXPALMOS5__
45ea509a
VZ
93// ----------------------------------------------------------------------------
94// constants
95// ----------------------------------------------------------------------------
c801d85f 96
52de37c7
VS
97#if defined(__VISUALC__) || defined(__DIGITALMARS__)
98 typedef int mode_t;
99#endif
100
0e0126c2
RR
101#ifdef __WXWINCE__
102 typedef long off_t;
103#else
6294ac2e
VZ
104 // define off_t
105 #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__)
106 #include <sys/types.h>
107 #else
108 typedef long off_t;
109 #endif
17dff81c 110#endif
45ea509a 111
65df77ec 112#if (defined(__VISUALC__) && !defined(__WXWINCE__)) || ( defined(__MWERKS__) && defined( __INTEL__) )
3f4a0c5b 113 typedef _off_t off_t;
2bdf7154 114#elif defined(__SYMANTEC__)
3f4a0c5b 115 typedef long off_t;
2d2ed20f 116#elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__)
8be97d65 117 typedef long off_t;
e2fc40b4
VZ
118#elif defined(__WXPALMOS5__)
119 typedef long off_t;
2432b92d
JS
120#endif
121
7af89395
VZ
122enum wxSeekMode
123{
45ea509a
VZ
124 wxFromStart,
125 wxFromCurrent,
126 wxFromEnd
7af89395 127};
45ea509a 128
0912690b 129enum wxFileKind
3c70014d 130{
0912690b
MW
131 wxFILE_KIND_UNKNOWN,
132 wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets
133 wxFILE_KIND_TERMINAL, // a tty
134 wxFILE_KIND_PIPE // a pipe
3c70014d
MW
135};
136
f6bcfd97
BP
137// ----------------------------------------------------------------------------
138// declare our versions of low level file functions: some compilers prepend
139// underscores to the usual names, some also have Unicode versions of them
140// ----------------------------------------------------------------------------
141
6294ac2e
VZ
142// Wrappers around Win32 api functions like CreateFile, ReadFile and such
143// Implemented in filefnwce.cpp
08c63240 144#if defined( __WXWINCE__)
6294ac2e
VZ
145 typedef __int64 wxFileOffset;
146 #define wxFileOffsetFmtSpec _("I64")
52de37c7
VS
147 WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *filename, int oflag, int WXUNUSED(pmode));
148 WXDLLIMPEXP_BASE int wxCRT_Access(const wxChar *name, int WXUNUSED(how));
aec1621e
VS
149 WXDLLIMPEXP_BASE int wxClose(int fd);
150 WXDLLIMPEXP_BASE int wxFsync(int WXUNUSED(fd));
151 WXDLLIMPEXP_BASE int wxRead(int fd, void *buf, unsigned int count);
152 WXDLLIMPEXP_BASE int wxWrite(int fd, const void *buf, unsigned int count);
153 WXDLLIMPEXP_BASE int wxEof(int fd);
154 WXDLLIMPEXP_BASE wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin);
6294ac2e 155 #define wxLSeek wxSeek
aec1621e 156 WXDLLIMPEXP_BASE wxFileOffset wxTell(int fd);
27b2dd53 157
c34db1be 158 // always Unicode under WinCE
52de37c7
VS
159 #define wxCRT_MkDir _wmkdir
160 #define wxCRT_RmDir _wrmdir
161 #define wxCRT_Stat _wstat
6294ac2e 162 #define wxStructStat struct _stat
2b2883a5 163#elif (defined(__WXMSW__) || defined(__OS2__)) && !defined(__WXPALMOS__) && \
dedcebb9
VZ
164 ( \
165 defined(__VISUALC__) || \
98225d02 166 defined(__MINGW64__) || \
dedcebb9
VZ
167 (defined(__MINGW32__) && !defined(__WINE__) && \
168 wxCHECK_W32API_VERSION(0, 5)) || \
169 defined(__MWERKS__) || \
170 defined(__DMC__) || \
171 defined(__WATCOMC__) || \
172 defined(__BORLANDC__) \
173 )
4004775e 174
4ae9be50 175 #undef wxHAS_HUGE_FILES
dedcebb9 176
76c36512
VZ
177 // detect compilers which have support for huge files
178 #if defined(__VISUALC__)
c26d982b 179 #define wxHAS_HUGE_FILES 1
98225d02 180 #elif defined(__MINGW32__) || defined(__MINGW64__)
4ae9be50 181 #define wxHAS_HUGE_FILES 1
1ad688c9
VZ
182 #elif defined(_LARGE_FILES)
183 #define wxHAS_HUGE_FILES 1
6294ac2e
VZ
184 #endif
185
1ad688c9
VZ
186 // other Windows compilers (DMC, Watcom, Metrowerks and Borland) don't have
187 // huge file support (or at least not all functions needed for it by wx)
188 // currently
189
1ad688c9 190 #ifdef wxHAS_HUGE_FILES
6294ac2e
VZ
191 typedef wxLongLong_t wxFileOffset;
192 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
193 #else
4004775e 194 typedef off_t wxFileOffset;
6294ac2e
VZ
195 #endif
196
f49ad976
VZ
197
198 // functions
199
200 // MSVC and compatible compilers prepend underscores to the POSIX function
201 // names, other compilers don't and even if their later versions usually do
202 // define the versions with underscores for MSVC compatibility, it's better
203 // to avoid using them as they're not present in earlier versions and
204 // always using the native functions spelling is easier than testing for
205 // the versions
3656eefc 206 #if defined(__BORLANDC__) || defined(__DMC__) || defined(__WATCOMC__) || defined(__MINGW64__)
f49ad976
VZ
207 #define wxPOSIX_IDENT(func) ::func
208 #else // by default assume MSVC-compatible names
209 #define wxPOSIX_IDENT(func) _ ## func
210 #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
211 #endif
212
e8f33d9e
VZ
213 // at least Borland 5.5 doesn't like "struct ::stat" so don't use the scope
214 // resolution operator present in wxPOSIX_IDENT for it
215 #ifdef __BORLANDC__
216 #define wxPOSIX_STRUCT(s) struct s
217 #else
218 #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
219 #endif
f49ad976
VZ
220
221 // first functions not working with strings, i.e. without ANSI/Unicode
222 // complications
223 #define wxClose wxPOSIX_IDENT(close)
6294ac2e
VZ
224
225 #if defined(__MWERKS__)
226 #if __MSL__ >= 0x6000
6d067eb6
VZ
227 #define wxRead(fd, buf, nCount) _read(fd, (void *)buf, nCount)
228 #define wxWrite(fd, buf, nCount) _write(fd, (void *)buf, nCount)
6294ac2e 229 #else
6d067eb6
VZ
230 #define wxRead(fd, buf, nCount)\
231 _read(fd, (const char *)buf, nCount)
232 #define wxWrite(fd, buf, nCount)\
233 _write(fd, (const char *)buf, nCount)
6294ac2e 234 #endif
f49ad976
VZ
235 #else // __MWERKS__
236 #define wxRead wxPOSIX_IDENT(read)
237 #define wxWrite wxPOSIX_IDENT(write)
6294ac2e 238 #endif
f49ad976 239
1ad688c9 240 #ifdef wxHAS_HUGE_FILES
3656eefc
SN
241 #ifndef __MINGW64__
242 #define wxSeek wxPOSIX_IDENT(lseeki64)
243 #define wxLseek wxPOSIX_IDENT(lseeki64)
244 #define wxTell wxPOSIX_IDENT(telli64)
245 #else
246 // unfortunately, mingw-W64 is somewhat inconsistent...
247 #define wxSeek _lseeki64
248 #define wxLseek _lseeki64
249 #define wxTell _telli64
250 #endif
dedcebb9 251 #else // !wxHAS_HUGE_FILES
f49ad976
VZ
252 #define wxSeek wxPOSIX_IDENT(lseek)
253 #define wxLseek wxPOSIX_IDENT(lseek)
254 #define wxTell wxPOSIX_IDENT(tell)
dedcebb9
VZ
255 #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
256
f49ad976 257 #ifndef __WATCOMC__
1b96afaa
VZ
258 #if !defined(__BORLANDC__) || (__BORLANDC__ > 0x540)
259 // NB: this one is not POSIX and always has the underscore
260 #define wxFsync _commit
dedcebb9 261
1b96afaa
VZ
262 // could be already defined by configure (Cygwin)
263 #ifndef HAVE_FSYNC
264 #define HAVE_FSYNC
265 #endif
266 #endif // BORLANDC
1239ac2e 267 #endif
f6bcfd97 268
f49ad976
VZ
269 #define wxEof wxPOSIX_IDENT(eof)
270
271 // then the functions taking strings
f6bcfd97 272 #if wxUSE_UNICODE
6de5b599 273 #if wxUSE_UNICODE_MSLU
6dad7fff
VZ
274 // implement the missing file functions in Win9x ourselves
275 #if defined( __VISUALC__ ) \
276 || ( defined(__MINGW32__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \
277 || ( defined(__MWERKS__) && defined(__WXMSW__) ) \
278 || ( defined(__BORLANDC__) && (__BORLANDC__ > 0x460) ) \
279 || defined(__DMC__)
6dad7fff 280
f49ad976
VZ
281 WXDLLIMPEXP_BASE int wxMSLU__wopen(const wxChar *name,
282 int flags, int mode);
283 WXDLLIMPEXP_BASE int wxMSLU__waccess(const wxChar *name,
284 int mode);
6dad7fff
VZ
285 WXDLLIMPEXP_BASE int wxMSLU__wmkdir(const wxChar *name);
286 WXDLLIMPEXP_BASE int wxMSLU__wrmdir(const wxChar *name);
f49ad976
VZ
287
288 WXDLLIMPEXP_BASE int
e8f33d9e 289 wxMSLU__wstat(const wxChar *name, wxPOSIX_STRUCT(stat) *buffer);
f49ad976
VZ
290 WXDLLIMPEXP_BASE int
291 wxMSLU__wstati64(const wxChar *name,
e8f33d9e 292 wxPOSIX_STRUCT(stati64) *buffer);
6dad7fff 293 #endif // Windows compilers with MSLU support
4876ba0b 294
52de37c7 295 #define wxCRT_Open wxMSLU__wopen
a62848fd 296
52de37c7
VS
297 #define wxCRT_Access wxMSLU__waccess
298 #define wxCRT_MkDir wxMSLU__wmkdir
299 #define wxCRT_RmDir wxMSLU__wrmdir
1ad688c9 300 #ifdef wxHAS_HUGE_FILES
52de37c7 301 #define wxCRT_Stat wxMSLU__wstati64
6294ac2e 302 #else
52de37c7 303 #define wxCRT_Stat wxMSLU__wstat
6294ac2e 304 #endif
f49ad976 305 #else // !wxUSE_UNICODE_MSLU
5c746f38 306 #ifdef __BORLANDC__
311b0403 307 #if __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
52de37c7
VS
308 WXDLLIMPEXP_BASE int wxCRT_Open(const wxChar *pathname,
309 int flags, mode_t mode);
311b0403 310 #else
52de37c7 311 #define wxCRT_Open _wopen
311b0403 312 #endif
52de37c7
VS
313 #define wxCRT_Access _waccess
314 #define wxCRT_MkDir _wmkdir
315 #define wxCRT_RmDir _wrmdir
5c746f38 316 #ifdef wxHAS_HUGE_FILES
52de37c7 317 #define wxCRT_Stat _wstati64
5c746f38 318 #else
52de37c7 319 #define wxCRT_Stat _wstat
5c746f38 320 #endif
6294ac2e 321 #else
52de37c7
VS
322 #define wxCRT_Open _wopen
323 #define wxCRT_Access _waccess
324 #define wxCRT_MkDir _wmkdir
325 #define wxCRT_RmDir _wrmdir
5c746f38 326 #ifdef wxHAS_HUGE_FILES
52de37c7 327 #define wxCRT_Stat _wstati64
5c746f38 328 #else
52de37c7 329 #define wxCRT_Stat _wstat
5c746f38 330 #endif
6294ac2e 331 #endif
f49ad976 332 #endif // wxUSE_UNICODE_MSLU/!wxUSE_UNICODE_MSLU
f6bcfd97 333 #else // !wxUSE_UNICODE
52de37c7
VS
334 #define wxCRT_Open wxPOSIX_IDENT(open)
335 #define wxCRT_Access wxPOSIX_IDENT(access)
336 #define wxCRT_MkDir wxPOSIX_IDENT(mkdir)
337 #define wxCRT_RmDir wxPOSIX_IDENT(rmdir)
1ad688c9 338 #ifdef wxHAS_HUGE_FILES
52de37c7 339 #define wxCRT_Stat wxPOSIX_IDENT(stati64)
6294ac2e 340 #else
1044b90c
SN
341 // Unfortunately Watcom is not consistent, so:-
342 #if defined(__OS2__) && defined(__WATCOMC__)
343 #define wxCRT_Stat _stat
344 #else
345 #define wxCRT_Stat wxPOSIX_IDENT(stat)
346 #endif
6294ac2e 347 #endif
dedcebb9 348 #endif // wxUSE_UNICODE/!wxUSE_UNICODE
f6bcfd97 349
6dabe332
WS
350 // Types: Notice that Watcom is the only compiler to have a wide char
351 // version of struct stat as well as a wide char stat function variant.
8aa61629
VZ
352 // This was dropped since OW 1.4 "for consistency across platforms".
353 //
354 // Borland is also special in that it uses _stat with Unicode functions
355 // (for MSVC compatibility?) but stat with ANSI ones
356 #ifdef __BORLANDC__
357 #if wxUSE_UNICODE
358 #define wxStructStat struct _stat
6294ac2e 359 #else
8aa61629 360 #define wxStructStat struct stat
6294ac2e 361 #endif
8aa61629
VZ
362 #else // !__BORLANDC__
363 #ifdef wxHAS_HUGE_FILES
364 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
365 #define wxStructStat struct _wstati64
366 #else
367 #define wxStructStat struct _stati64
368 #endif
6294ac2e 369 #else
8aa61629
VZ
370 #if wxUSE_UNICODE && wxONLY_WATCOM_EARLIER_THAN(1,4)
371 #define wxStructStat struct _wstat
372 #else
373 #define wxStructStat struct _stat
374 #endif
6294ac2e 375 #endif
8aa61629 376 #endif // __BORLANDC__/!__BORLANDC__
f6bcfd97
BP
377
378 // constants (unless already defined by the user code)
f49ad976 379 #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
eb84314b
VZ
380 #ifndef O_RDONLY
381 #define O_RDONLY _O_RDONLY
382 #define O_WRONLY _O_WRONLY
383 #define O_RDWR _O_RDWR
384 #define O_EXCL _O_EXCL
385 #define O_CREAT _O_CREAT
386 #define O_BINARY _O_BINARY
387 #endif
388
389 #ifndef S_IFMT
390 #define S_IFMT _S_IFMT
391 #define S_IFDIR _S_IFDIR
392 #define S_IFREG _S_IFREG
393 #endif
f49ad976 394 #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
6294ac2e 395
1ad688c9 396 #ifdef wxHAS_HUGE_FILES
3d3c6c45
MW
397 // wxFile is present and supports large files. Currently wxFFile
398 // doesn't have large file support with any Windows compiler (even
399 // Win64 ones).
400 #if wxUSE_FILE
82b99cf9 401 #define wxHAS_LARGE_FILES
3d3c6c45
MW
402 #endif
403 #endif
dedcebb9
VZ
404
405 // it's a private define, undefine it so that nobody gets tempted to use it
4ae9be50 406 #undef wxHAS_HUGE_FILES
9b4da627
VZ
407#elif defined (__WXPALMOS__)
408 typedef off_t wxFileOffset;
409#ifdef _LARGE_FILES
410 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
411 wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t), BadFileSizeType );
412 // wxFile is present and supports large files
413 #ifdef wxUSE_FILE
414 #define wxHAS_LARGE_FILES
415 #endif
416 // wxFFile is present and supports large files
417 #if SIZEOF_LONG == 8 || defined HAVE_FSEEKO
418 #define wxHAS_LARGE_FFILES
419 #endif
420#else
421 #define wxFileOffsetFmtSpec _T("")
422#endif
423 #define wxClose close
424 #define wxRead ::read
425 #define wxWrite ::write
426 #define wxLseek lseek
427 #define wxSeek lseek
428 #define wxFsync fsync
429 #define wxEof eof
430
431 #define wxCRT_MkDir mkdir
432 #define wxCRT_RmDir rmdir
433
434 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
435
436 #define wxStructStat struct stat
437
438 #define wxCRT_Open open
439 #define wxCRT_Stat svfs_stat
440 #define wxCRT_Lstat lstat
441 #define wxCRT_Access access
442
443 #define wxHAS_NATIVE_LSTAT
dedcebb9 444#else // Unix or Windows using unknown compiler, assume POSIX supported
6294ac2e
VZ
445 typedef off_t wxFileOffset;
446 #ifdef _LARGE_FILES
447 #define wxFileOffsetFmtSpec wxLongLongFmtSpec
bd3cea7d
VZ
448 wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
449 BadFileSizeType );
3d3c6c45
MW
450 // wxFile is present and supports large files
451 #ifdef wxUSE_FILE
82b99cf9 452 #define wxHAS_LARGE_FILES
3d3c6c45
MW
453 #endif
454 // wxFFile is present and supports large files
455 #if SIZEOF_LONG == 8 || defined HAVE_FSEEKO
82b99cf9 456 #define wxHAS_LARGE_FFILES
3d3c6c45 457 #endif
6294ac2e
VZ
458 #else
459 #define wxFileOffsetFmtSpec _T("")
460 #endif
f6bcfd97 461 // functions
f6bcfd97 462 #define wxClose close
6294ac2e
VZ
463 #define wxRead ::read
464 #define wxWrite ::write
f6bcfd97 465 #define wxLseek lseek
6294ac2e 466 #define wxSeek lseek
52ca5b59 467 #define wxFsync fsync
f6bcfd97
BP
468 #define wxEof eof
469
52de37c7
VS
470 #define wxCRT_MkDir mkdir
471 #define wxCRT_RmDir rmdir
f6bcfd97
BP
472
473 #define wxTell(fd) lseek(fd, 0, SEEK_CUR)
474
f6bcfd97 475 #define wxStructStat struct stat
a62848fd 476
52de37c7
VS
477 #define wxCRT_Open open
478 #define wxCRT_Stat stat
479 #define wxCRT_Lstat lstat
480 #define wxCRT_Access access
194b2267 481
dedcebb9 482 #define wxHAS_NATIVE_LSTAT
06e66bd0 483#endif // platforms
f6bcfd97 484
52de37c7
VS
485// if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
486// wxCRT_Stat to avoid #ifdefs in the code using it
487#ifndef wxHAS_NATIVE_LSTAT
488 #define wxCRT_Lstat wxCRT_Stat
489#endif
490
52de37c7
VS
491inline int wxAccess(const wxString& path, mode_t mode)
492 { return wxCRT_Access(path.fn_str(), mode); }
493inline int wxOpen(const wxString& path, int flags, mode_t mode)
494 { return wxCRT_Open(path.fn_str(), flags, mode); }
d6f2a891
VZ
495
496// FIXME-CE: provide our own implementations of the missing CRT functions
497#ifndef __WXWINCE__
498inline int wxStat(const wxString& path, wxStructStat *buf)
499 { return wxCRT_Stat(path.fn_str(), buf); }
500inline int wxLstat(const wxString& path, wxStructStat *buf)
501 { return wxCRT_Lstat(path.fn_str(), buf); }
52de37c7
VS
502inline int wxRmDir(const wxString& path)
503 { return wxCRT_RmDir(path.fn_str()); }
2b2883a5 504#if defined(__WINDOWS__) || (defined(__OS2__) && defined(__WATCOMC__))
52de37c7
VS
505inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
506 { return wxCRT_MkDir(path.fn_str()); }
507#else
508inline int wxMkDir(const wxString& path, mode_t mode)
509 { return wxCRT_MkDir(path.fn_str(), mode); }
510#endif
d6f2a891 511#endif // !__WXWINCE__
52de37c7 512
3d3c6c45
MW
513#ifdef O_BINARY
514 #define wxO_BINARY O_BINARY
515#else
516 #define wxO_BINARY 0
517#endif
518
06e66bd0
VZ
519#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
520//
521// VisualAge C++ V4.0 cannot have any external linkage const decs
522// in headers included by more than one primary source
523//
30984dea 524extern const int wxInvalidOffset;
06e66bd0 525#else
30984dea 526const int wxInvalidOffset = -1;
06e66bd0 527#endif
f6bcfd97 528
45ea509a
VZ
529// ----------------------------------------------------------------------------
530// functions
531// ----------------------------------------------------------------------------
bddd7a8d 532WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
c801d85f
KB
533
534// does the path exist? (may have or not '/' or '\\' at the end)
e960c20e 535WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
c801d85f 536
bddd7a8d 537WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
c801d85f
KB
538
539// Get filename
bddd7a8d
VZ
540WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
541WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
c801d85f
KB
542
543// Get directory
bddd7a8d 544WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
c801d85f 545
47d281e6
FM
546// all deprecated functions below are deprecated in favour of wxFileName's methods
547#if WXWIN_COMPATIBILITY_2_8
c801d85f 548
47d281e6
FM
549wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(char *s) );
550wxDEPRECATED( WXDLLIMPEXP_BASE void wxDos2UnixFilename(wchar_t *s) );
551
220ea2b9
VZ
552wxDEPRECATED_BUT_USED_INTERNALLY(
553 WXDLLIMPEXP_BASE void wxUnix2DosFilename(char *s) );
554wxDEPRECATED_BUT_USED_INTERNALLY(
555 WXDLLIMPEXP_BASE void wxUnix2DosFilename(wchar_t *s) );
c801d85f
KB
556
557// Strip the extension, in situ
47d281e6
FM
558wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(char *buffer) );
559wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wchar_t *buffer) );
560wxDEPRECATED( WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer) );
561 // DEPRECATED: construct a wxFileName, use ClearExt() and then GetFullPath()
c801d85f 562
ade35f11 563// Get a temporary filename
d3b9f782 564wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = NULL) );
48598c66 565wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf) );
c801d85f
KB
566
567// Expand file name (~/ and ${OPENWINHOME}/ stuff)
48598c66
FM
568wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxExpandPath(char *dest, const wxString& path) );
569wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxExpandPath(wchar_t *dest, const wxString& path) );
47d281e6 570 // DEPRECATED: use wxFileName::Normalize(wxPATH_NORM_ENV_VARS)
c801d85f
KB
571
572// Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib)
573// and make (if under the home tree) relative to home
574// [caller must copy-- volatile]
47d281e6 575wxDEPRECATED(
bddd7a8d 576WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename,
ade35f11 577 const wxString& envname = wxEmptyString,
47d281e6
FM
578 const wxString& user = wxEmptyString) );
579 // DEPRECATED: use wxFileName::ReplaceEnvVariable and wxFileName::ReplaceHomeDir
c801d85f
KB
580
581// Destructive removal of /./ and /../ stuff
48598c66
FM
582wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE char* wxRealPath(char *path) );
583wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wchar_t* wxRealPath(wchar_t *path) );
584wxDEPRECATED_BUT_USED_INTERNALLY( WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path) );
47d281e6 585 // DEPRECATED: use wxFileName::Normalize instead
c801d85f
KB
586
587// Allocate a copy of the full absolute path
47d281e6
FM
588wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path) );
589 // DEPRECATED: use wxFileName::MakeAbsolute instead
590#endif
c801d85f
KB
591
592// Get first file name matching given wild card.
593// Flags are reserved for future use.
594#define wxFILE 1
595#define wxDIR 2
52de37c7 596WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
bddd7a8d 597WXDLLIMPEXP_BASE wxString wxFindNextFile();
c801d85f
KB
598
599// Does the pattern contain wildcards?
bddd7a8d 600WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
c801d85f
KB
601
602// Does the pattern match the text (usually a filename)?
a62848fd 603// If dot_special is true, doesn't match * against . (eliminating
c801d85f 604// `hidden' dot files)
a62848fd 605WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true);
c801d85f
KB
606
607// Concatenate two files to form third
bddd7a8d 608WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3);
c801d85f
KB
609
610// Copy file1 to file2
bddd7a8d 611WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2,
a62848fd 612 bool overwrite = true);
c801d85f
KB
613
614// Remove file
bddd7a8d 615WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
c801d85f
KB
616
617// Rename file
57e988b8 618WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2, bool overwrite = true);
c801d85f
KB
619
620// Get current working directory.
2587df2c
VS
621#if WXWIN_COMPATIBILITY_2_6
622// If buf is NULL, allocates space using new, else
623// copies into buf.
624// IMPORTANT NOTE getcwd is know not to work under some releases
625// of Win32s 1.3, according to MS release notes!
d3b9f782 626wxDEPRECATED( WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = NULL, int sz = 1000) );
2587df2c
VS
627// new and preferred version of wxGetWorkingDirectory
628// NB: can't have the same name because of overloading ambiguity
629#endif // WXWIN_COMPATIBILITY_2_6
bddd7a8d 630WXDLLIMPEXP_BASE wxString wxGetCwd();
c801d85f
KB
631
632// Set working directory
bddd7a8d 633WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
c801d85f
KB
634
635// Make directory
bddd7a8d 636WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = 0777);
c801d85f
KB
637
638// Remove directory. Flags reserved for future use.
bddd7a8d 639WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
c801d85f 640
3c70014d 641// Return the type of an open file
0912690b 642WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
9802983f 643WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
3c70014d 644
2587df2c
VS
645#if WXWIN_COMPATIBILITY_2_6
646// compatibility defines, don't use in new code
647wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) );
648inline bool wxPathExists(const wxChar *pszPathName)
649{
650 return wxDirExists(pszPathName);
651}
652#endif //WXWIN_COMPATIBILITY_2_6
653
3ff07edb
RR
654// permissions; these functions work both on files and directories:
655WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
656WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
657WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
658
ff69a290 659// ----------------------------------------------------------------------------
c801d85f 660// separators in file names
ff69a290
VZ
661// ----------------------------------------------------------------------------
662
663// between file name and extension
223d09f6 664#define wxFILE_SEP_EXT wxT('.')
ff69a290
VZ
665
666// between drive/volume name and the path
223d09f6 667#define wxFILE_SEP_DSK wxT(':')
ff69a290
VZ
668
669// between the path components
223d09f6
KB
670#define wxFILE_SEP_PATH_DOS wxT('\\')
671#define wxFILE_SEP_PATH_UNIX wxT('/')
844f90fb 672#define wxFILE_SEP_PATH_MAC wxT(':')
ff69a290 673#define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']'
c801d85f
KB
674
675// separator in the path list (as in PATH environment variable)
03e11df5
GD
676// there is no PATH variable in Classic Mac OS so just use the
677// semicolon (it must be different from the file name separator)
c801d85f 678// NB: these are strings and not characters on purpose!
223d09f6
KB
679#define wxPATH_SEP_DOS wxT(";")
680#define wxPATH_SEP_UNIX wxT(":")
03e11df5 681#define wxPATH_SEP_MAC wxT(";")
c801d85f
KB
682
683// platform independent versions
77a80672
VZ
684#if defined(__UNIX__) && !defined(__OS2__)
685 // CYGWIN also uses UNIX settings
7af89395
VZ
686 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
687 #define wxPATH_SEP wxPATH_SEP_UNIX
e2fc40b4
VZ
688#elif defined(__WXPALMOS__)
689 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX
690 #define wxPATH_SEP wxPATH_SEP_UNIX
844f90fb 691#elif defined(__MAC__)
bedaf53e 692 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC
3369df87 693 #define wxPATH_SEP wxPATH_SEP_MAC
1777b9bb 694#else // Windows and OS/2
7af89395
VZ
695 #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS
696 #define wxPATH_SEP wxPATH_SEP_DOS
c801d85f
KB
697#endif // Unix/Windows
698
92abb45d
VZ
699// this is useful for wxString::IsSameAs(): to compare two file names use
700// filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
28e5e577 701#if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__)
a62848fd 702 #define wxARE_FILENAMES_CASE_SENSITIVE true
3369df87 703#else // Windows, Mac OS and OS/2
a62848fd 704 #define wxARE_FILENAMES_CASE_SENSITIVE false
92abb45d
VZ
705#endif // Unix/Windows
706
c801d85f 707// is the char a path separator?
9d2f3c71 708inline bool wxIsPathSeparator(wxChar c)
903b61cc
VZ
709{
710 // under DOS/Windows we should understand both Unix and DOS file separators
a62848fd 711#if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__)
903b61cc
VZ
712 return c == wxFILE_SEP_PATH;
713#else
714 return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
715#endif
716}
c801d85f
KB
717
718// does the string ends with path separator?
52de37c7 719WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
c801d85f 720
47d281e6 721#if WXWIN_COMPATIBILITY_2_8
92abb45d
VZ
722// split the full path into path (including drive for DOS), name and extension
723// (understands both '/' and '\\')
47d281e6
FM
724wxDEPRECATED( WXDLLIMPEXP_BASE void wxSplitPath(const wxString& fileName,
725 wxString *pstrPath,
726 wxString *pstrName,
727 wxString *pstrExt) );
728#endif
92abb45d 729
c801d85f 730// find a file in a list of directories, returns false if not found
52de37c7 731WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
c801d85f 732
631f1bfe
JS
733// Get the OS directory if appropriate (such as the Windows directory).
734// On non-Windows platform, probably just return the empty string.
bddd7a8d 735WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
631f1bfe 736
2c5e5cbd
VS
737#if wxUSE_DATETIME
738
a47ce4a7 739// Get file modification time
bddd7a8d 740WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
a47ce4a7 741
2c5e5cbd
VS
742#endif // wxUSE_DATETIME
743
9e152a55
WS
744// Parses the wildCard, returning the number of filters.
745// Returns 0 if none or if there's a problem,
746// The arrays will contain an equal number of items found before the error.
747// wildCard is in the form:
748// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
daf32463 749WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
9e152a55 750
45ea509a
VZ
751// ----------------------------------------------------------------------------
752// classes
753// ----------------------------------------------------------------------------
754
8482e4bd
VZ
755#ifdef __UNIX__
756
757// set umask to the given value in ctor and reset it to the old one in dtor
758class WXDLLIMPEXP_BASE wxUmaskChanger
759{
760public:
761 // change the umask to the given one if it is not -1: this allows to write
762 // the same code whether you really want to change umask or not, as is in
763 // wxFileConfig::Flush() for example
764 wxUmaskChanger(int umaskNew)
765 {
835fab50 766 m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
8482e4bd
VZ
767 }
768
769 ~wxUmaskChanger()
770 {
771 if ( m_umaskOld != -1 )
772 umask((mode_t)m_umaskOld);
773 }
774
775private:
776 int m_umaskOld;
777};
778
779// this macro expands to an "anonymous" wxUmaskChanger object under Unix and
780// nothing elsewhere
781#define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
782
783#else // !__UNIX__
784
785#define wxCHANGE_UMASK(m)
786
787#endif // __UNIX__/!__UNIX__
788
789
c801d85f 790// Path searching
8daf3c36 791class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
c801d85f 792{
a6f6393c 793public:
8daf3c36
VZ
794 wxPathList() {}
795 wxPathList(const wxArrayString &arr)
796 { Add(arr); }
797
7af89395
VZ
798 // Adds all paths in environment variable
799 void AddEnvList(const wxString& envVariable);
c330a2cf 800
8daf3c36 801 // Adds given path to this list
34e2d943 802 bool Add(const wxString& path);
8daf3c36
VZ
803 void Add(const wxArrayString &paths);
804
7af89395 805 // Find the first full path for which the file exists
8daf3c36
VZ
806 wxString FindValidPath(const wxString& filename) const;
807
7af89395
VZ
808 // Find the first full path for which the file exists; ensure it's an
809 // absolute path that gets returned.
8daf3c36
VZ
810 wxString FindAbsoluteValidPath(const wxString& filename) const;
811
7af89395 812 // Given full path and filename, add path to list
34e2d943 813 bool EnsureFileAccessible(const wxString& path);
2587df2c
VS
814
815#if WXWIN_COMPATIBILITY_2_6
816 // Returns true if the path is in the list
817 wxDEPRECATED( bool Member(const wxString& path) const );
818#endif
c801d85f
KB
819};
820
8daf3c36 821#endif // _WX_FILEFN_H_