]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | |
65571936 | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _FILEFN_H_ |
13 | #define _FILEFN_H_ | |
c801d85f | 14 | |
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
7af89395 | 16 | #pragma interface "filefn.h" |
c801d85f KB |
17 | #endif |
18 | ||
ed58dbea | 19 | #include "wx/list.h" |
b76069e2 | 20 | #include "wx/arrstr.h" |
e49f47aa | 21 | |
6294ac2e VZ |
22 | #ifdef __WXWINCE__ |
23 | #include "wx/msw/wince/time.h" | |
24 | #include "wx/msw/private.h" | |
25 | #else | |
26 | #include <time.h> | |
0e0126c2 | 27 | #endif |
a47ce4a7 | 28 | |
6294ac2e VZ |
29 | #ifdef __WXWINCE__ |
30 | // Nothing | |
31 | #elif !defined(__MWERKS__) | |
32 | #include <sys/types.h> | |
33 | #include <sys/stat.h> | |
34 | #else | |
35 | #ifdef __MACH__ | |
36 | #include <sys/types.h> | |
37 | #include <utime.h> | |
38 | #include <sys/stat.h> | |
39 | #include <unistd.h> | |
40 | #else | |
41 | #include <stat.h> | |
42 | #include <unistd.h> | |
43 | #include <unix.h> | |
44 | #endif | |
45 | #endif | |
46 | ||
47 | #ifdef __OS2__ | |
48 | // need to check for __OS2__ first since currently both | |
49 | // __OS2__ and __UNIX__ are defined. | |
50 | #include <process.h> | |
51 | #include "wx/os2/private.h" | |
0872eaf9 WS |
52 | #ifdef __WATCOMC__ |
53 | #include <direct.h> | |
54 | #endif | |
6294ac2e VZ |
55 | #include <io.h> |
56 | #ifdef __EMX__ | |
57 | #include <unistd.h> | |
58 | #endif | |
59 | #elif defined(__UNIX__) | |
60 | #include <unistd.h> | |
61 | #include <dirent.h> | |
62 | #endif | |
63 | ||
64 | #if defined(__WINDOWS__) && !defined(__WXMICROWIN__) | |
8490b71b | 65 | #if !defined( __GNUWIN32__ ) && !defined( __MWERKS__ ) && !defined(__SALFORDC__) && !defined(__WXWINCE__) && !defined(__CYGWIN__) |
6294ac2e VZ |
66 | #include <direct.h> |
67 | #include <dos.h> | |
68 | #include <io.h> | |
69 | #endif // __WINDOWS__ | |
70 | #endif // native Win compiler | |
71 | ||
72 | #if defined(__DOS__) | |
73 | #ifdef __WATCOMC__ | |
74 | #include <direct.h> | |
75 | #include <dos.h> | |
76 | #include <io.h> | |
77 | #endif | |
78 | #ifdef __DJGPP__ | |
79 | #include <io.h> | |
80 | #include <unistd.h> | |
81 | #endif | |
82 | #endif | |
83 | ||
84 | #ifdef __BORLANDC__ // Please someone tell me which version of Borland needs | |
85 | // this (3.1 I believe) and how to test for it. | |
86 | // If this works for Borland 4.0 as well, then no worries. | |
87 | #include <dir.h> | |
88 | #endif | |
89 | ||
90 | #ifdef __SALFORDC__ | |
91 | #include <dir.h> | |
92 | #include <unix.h> | |
93 | #endif | |
94 | ||
95 | #ifndef __WXWINCE__ | |
96 | #include <fcntl.h> // O_RDONLY &c | |
97 | #endif | |
45ea509a VZ |
98 | // ---------------------------------------------------------------------------- |
99 | // constants | |
100 | // ---------------------------------------------------------------------------- | |
c801d85f | 101 | |
0e0126c2 RR |
102 | #ifdef __WXWINCE__ |
103 | typedef long off_t; | |
104 | #else | |
6294ac2e VZ |
105 | // define off_t |
106 | #if !defined(__WXMAC__) || defined(__UNIX__) || defined(__MACH__) | |
107 | #include <sys/types.h> | |
108 | #else | |
109 | typedef long off_t; | |
110 | #endif | |
17dff81c | 111 | #endif |
45ea509a | 112 | |
65df77ec | 113 | #if (defined(__VISUALC__) && !defined(__WXWINCE__)) || ( defined(__MWERKS__) && defined( __INTEL__) ) |
3f4a0c5b | 114 | typedef _off_t off_t; |
2bdf7154 | 115 | #elif defined(__SYMANTEC__) |
3f4a0c5b | 116 | typedef long off_t; |
2d2ed20f | 117 | #elif defined(__MWERKS__) && !defined(__INTEL__) && !defined(__MACH__) |
8be97d65 | 118 | typedef long off_t; |
2432b92d JS |
119 | #endif |
120 | ||
7af89395 VZ |
121 | enum wxSeekMode |
122 | { | |
45ea509a VZ |
123 | wxFromStart, |
124 | wxFromCurrent, | |
125 | wxFromEnd | |
7af89395 | 126 | }; |
45ea509a | 127 | |
0912690b | 128 | enum wxFileKind |
3c70014d | 129 | { |
0912690b MW |
130 | wxFILE_KIND_UNKNOWN, |
131 | wxFILE_KIND_DISK, // a file supporting seeking to arbitrary offsets | |
132 | wxFILE_KIND_TERMINAL, // a tty | |
133 | wxFILE_KIND_PIPE // a pipe | |
3c70014d MW |
134 | }; |
135 | ||
f6bcfd97 BP |
136 | // ---------------------------------------------------------------------------- |
137 | // declare our versions of low level file functions: some compilers prepend | |
138 | // underscores to the usual names, some also have Unicode versions of them | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
6294ac2e VZ |
141 | // Wrappers around Win32 api functions like CreateFile, ReadFile and such |
142 | // Implemented in filefnwce.cpp | |
08c63240 | 143 | #if defined( __WXWINCE__) |
6294ac2e VZ |
144 | typedef __int64 wxFileOffset; |
145 | #define wxFileOffsetFmtSpec _("I64") | |
146 | int wxOpen(const wxChar *filename, int oflag, int WXUNUSED(pmode)); | |
147 | int wxAccess(const wxChar *name, int WXUNUSED(how)); | |
148 | int wxClose(int fd); | |
149 | int wxFsync(int WXUNUSED(fd)); | |
150 | int wxRead(int fd, void *buf, unsigned int count); | |
151 | int wxWrite(int fd, const void *buf, unsigned int count); | |
152 | int wxEof(int fd); | |
153 | wxFileOffset wxSeek(int fd, wxFileOffset offset, int origin); | |
154 | #define wxLSeek wxSeek | |
155 | wxFileOffset wxTell(int fd); | |
27b2dd53 | 156 | |
c34db1be RR |
157 | // always Unicode under WinCE |
158 | #define wxMkDir _wmkdir | |
159 | #define wxRmDir _wrmdir | |
160 | #define wxStat _wstat | |
6294ac2e VZ |
161 | #define wxStructStat struct _stat |
162 | ||
f6bcfd97 | 163 | // Microsoft compiler loves underscores, feed them to it |
6294ac2e | 164 | #elif defined( __VISUALC__ ) \ |
5283098e | 165 | || ( defined(__MINGW32__) && !defined(__WINE__) && wxCHECK_W32API_VERSION( 0, 5 ) ) \ |
18da7cf2 | 166 | || ( defined(__MWERKS__) && defined(__WXMSW__) ) \ |
ba1e9d6c | 167 | || ( defined(__DMC__) && defined(__WXMSW__) ) \ |
18da7cf2 | 168 | || ( defined(__WATCOMC__) && defined(__WXMSW__) ) |
6294ac2e | 169 | |
115148f7 VZ |
170 | // detect compilers which have support for huge files (currently only |
171 | // Digital Mars doesn't) | |
4055ed82 | 172 | #ifndef __WXPALMOS__ |
4004775e | 173 | #include "wx/msw/private.h" |
ffecfa5a | 174 | #endif |
4004775e | 175 | |
4ae9be50 | 176 | #undef wxHAS_HUGE_FILES |
115148f7 | 177 | #if defined(__MINGW32__) |
4ae9be50 | 178 | #define wxHAS_HUGE_FILES 1 |
6d067eb6 | 179 | #elif defined(__MWERKS__) |
4ae9be50 | 180 | #define wxHAS_HUGE_FILES 0 |
115148f7 | 181 | #elif defined(__DMC__) |
4ae9be50 | 182 | #define wxHAS_HUGE_FILES 0 |
115148f7 | 183 | #elif ((_INTEGRAL_MAX_BITS >= 64) || defined(_LARGE_FILES)) |
4ae9be50 | 184 | #define wxHAS_HUGE_FILES 1 |
6294ac2e | 185 | #else |
4ae9be50 | 186 | #define wxHAS_HUGE_FILES 0 |
6294ac2e VZ |
187 | #endif |
188 | ||
f6bcfd97 | 189 | // functions |
6294ac2e VZ |
190 | #if defined(__BORLANDC__) || defined(__WATCOMC__) |
191 | #define _tell tell | |
192 | #endif | |
193 | ||
4ae9be50 | 194 | #if wxHAS_HUGE_FILES |
6294ac2e VZ |
195 | typedef wxLongLong_t wxFileOffset; |
196 | #define wxFileOffsetFmtSpec wxLongLongFmtSpec | |
197 | #else | |
4004775e | 198 | typedef off_t wxFileOffset; |
6294ac2e VZ |
199 | #endif |
200 | ||
f6bcfd97 | 201 | #define wxClose _close |
6294ac2e VZ |
202 | |
203 | #if defined(__MWERKS__) | |
204 | #if __MSL__ >= 0x6000 | |
6d067eb6 VZ |
205 | #define wxRead(fd, buf, nCount) _read(fd, (void *)buf, nCount) |
206 | #define wxWrite(fd, buf, nCount) _write(fd, (void *)buf, nCount) | |
6294ac2e | 207 | #else |
6d067eb6 VZ |
208 | #define wxRead(fd, buf, nCount)\ |
209 | _read(fd, (const char *)buf, nCount) | |
210 | #define wxWrite(fd, buf, nCount)\ | |
211 | _write(fd, (const char *)buf, nCount) | |
6294ac2e VZ |
212 | #endif |
213 | #else | |
30984dea | 214 | #if defined(__DMC__) || defined(__WATCOMC__) |
6294ac2e VZ |
215 | #define wxRead ::read |
216 | #define wxWrite ::write | |
217 | #else | |
218 | #define wxRead _read | |
219 | #define wxWrite _write | |
220 | #endif | |
221 | #endif | |
4ae9be50 | 222 | #if wxHAS_HUGE_FILES |
6294ac2e VZ |
223 | #define wxSeek _lseeki64 |
224 | #define wxLseek _lseeki64 | |
225 | #define wxTell _telli64 | |
226 | #else | |
227 | #define wxSeek _lseek | |
228 | #define wxLseek _lseek | |
229 | #define wxTell _tell | |
230 | #endif | |
f6bcfd97 | 231 | #define wxFsync _commit |
1239ac2e WS |
232 | #if defined(__WATCOMC__) |
233 | #define wxEof ::eof | |
234 | #else | |
235 | #define wxEof _eof | |
236 | #endif | |
f6bcfd97 | 237 | |
f6bcfd97 | 238 | #if wxUSE_UNICODE |
6de5b599 | 239 | #if wxUSE_UNICODE_MSLU |
3e6477f4 | 240 | #define wxOpen wxMSLU__wopen |
a62848fd | 241 | |
3d5231db VS |
242 | #define wxAccess wxMSLU__waccess |
243 | #define wxMkDir wxMSLU__wmkdir | |
244 | #define wxRmDir wxMSLU__wrmdir | |
4ae9be50 | 245 | #if wxHAS_HUGE_FILES |
6294ac2e VZ |
246 | #define wxStat wxMSLU__wstati64 |
247 | #else | |
248 | #define wxStat wxMSLU__wstat | |
249 | #endif | |
6de5b599 VS |
250 | #else |
251 | #define wxOpen _wopen | |
3d5231db VS |
252 | #define wxAccess _waccess |
253 | #define wxMkDir _wmkdir | |
254 | #define wxRmDir _wrmdir | |
4ae9be50 | 255 | #if wxHAS_HUGE_FILES |
6294ac2e VZ |
256 | #define wxStat _wstati64 |
257 | #else | |
258 | #define wxStat _wstat | |
259 | #endif | |
6de5b599 | 260 | #endif |
f6bcfd97 | 261 | #else // !wxUSE_UNICODE |
6294ac2e VZ |
262 | #ifdef __BORLANDC__ |
263 | #define wxOpen open | |
264 | #else | |
265 | #define wxOpen _open | |
266 | #endif | |
f6bcfd97 | 267 | #define wxAccess _access |
f6bcfd97 | 268 | #define wxMkDir _mkdir |
6294ac2e VZ |
269 | #ifdef __WATCOMC__ |
270 | #define wxRmDir rmdir | |
271 | #else | |
272 | #define wxRmDir _rmdir | |
273 | #endif | |
4ae9be50 | 274 | #if wxHAS_HUGE_FILES |
6294ac2e VZ |
275 | #define wxStat _stati64 |
276 | #else | |
277 | #define wxStat _stat | |
278 | #endif | |
f6bcfd97 BP |
279 | #endif |
280 | ||
e302e0c1 VZ |
281 | // types: notice that Watcom is the only compiler to have a wide char |
282 | // version of struct stat as well as a wide char stat function variant | |
4ae9be50 | 283 | #if wxHAS_HUGE_FILES |
e302e0c1 | 284 | #if wxUSE_UNICODE && defined(__WATCOMC__) |
6294ac2e VZ |
285 | #define wxStructStat struct _wstati64 |
286 | #else | |
287 | #define wxStructStat struct _stati64 | |
288 | #endif | |
289 | #else | |
e302e0c1 | 290 | #if wxUSE_UNICODE && defined(__WATCOMC__) |
6294ac2e VZ |
291 | #define wxStructStat struct _wstat |
292 | #else | |
293 | #define wxStructStat struct _stat | |
294 | #endif | |
295 | #endif | |
f6bcfd97 BP |
296 | |
297 | // constants (unless already defined by the user code) | |
4055ed82 | 298 | #if !defined(__BORLANDC__) && !defined(__WATCOMC__) && !defined(__WXPALMOS__) |
eb84314b VZ |
299 | #ifndef O_RDONLY |
300 | #define O_RDONLY _O_RDONLY | |
301 | #define O_WRONLY _O_WRONLY | |
302 | #define O_RDWR _O_RDWR | |
303 | #define O_EXCL _O_EXCL | |
304 | #define O_CREAT _O_CREAT | |
305 | #define O_BINARY _O_BINARY | |
306 | #endif | |
307 | ||
308 | #ifndef S_IFMT | |
309 | #define S_IFMT _S_IFMT | |
310 | #define S_IFDIR _S_IFDIR | |
311 | #define S_IFREG _S_IFREG | |
312 | #endif | |
313 | #endif | |
6294ac2e VZ |
314 | |
315 | // It's a private define, undefine it so nobody gets tempted to use it | |
4ae9be50 | 316 | #undef wxHAS_HUGE_FILES |
06e66bd0 | 317 | #else // Unix platforms using configure |
6294ac2e VZ |
318 | typedef off_t wxFileOffset; |
319 | #ifdef _LARGE_FILES | |
320 | #define wxFileOffsetFmtSpec wxLongLongFmtSpec | |
bd3cea7d VZ |
321 | wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t), |
322 | BadFileSizeType ); | |
6294ac2e VZ |
323 | #else |
324 | #define wxFileOffsetFmtSpec _T("") | |
325 | #endif | |
f6bcfd97 | 326 | // functions |
f6bcfd97 | 327 | #define wxClose close |
6294ac2e VZ |
328 | #define wxRead ::read |
329 | #define wxWrite ::write | |
f6bcfd97 | 330 | #define wxLseek lseek |
6294ac2e | 331 | #define wxSeek lseek |
f6bcfd97 | 332 | #define wxFsync commit |
f6bcfd97 BP |
333 | #define wxEof eof |
334 | ||
335 | #define wxMkDir mkdir | |
336 | #define wxRmDir rmdir | |
337 | ||
338 | #define wxTell(fd) lseek(fd, 0, SEEK_CUR) | |
339 | ||
f6bcfd97 | 340 | #define wxStructStat struct stat |
a62848fd | 341 | |
6294ac2e VZ |
342 | #if wxUSE_UNICODE |
343 | #define wxNEED_WX_UNISTD_H | |
344 | #if defined(__DMC__) | |
345 | typedef unsigned long mode_t; | |
346 | #endif | |
347 | WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf ); | |
348 | WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode ); | |
349 | WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode ); | |
350 | #else | |
351 | #define wxOpen open | |
352 | #define wxStat stat | |
353 | #define wxAccess access | |
354 | #endif | |
06e66bd0 | 355 | #endif // platforms |
f6bcfd97 | 356 | |
06e66bd0 VZ |
357 | #if defined(__VISAGECPP__) && __IBMCPP__ >= 400 |
358 | // | |
359 | // VisualAge C++ V4.0 cannot have any external linkage const decs | |
360 | // in headers included by more than one primary source | |
361 | // | |
30984dea | 362 | extern const int wxInvalidOffset; |
06e66bd0 | 363 | #else |
30984dea | 364 | const int wxInvalidOffset = -1; |
06e66bd0 | 365 | #endif |
f6bcfd97 | 366 | |
45ea509a VZ |
367 | // ---------------------------------------------------------------------------- |
368 | // functions | |
369 | // ---------------------------------------------------------------------------- | |
bddd7a8d | 370 | WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename); |
c801d85f KB |
371 | |
372 | // does the path exist? (may have or not '/' or '\\' at the end) | |
da865fdd | 373 | WXDLLIMPEXP_BASE bool wxDirExists(const wxChar *pszPathName); |
c801d85f | 374 | |
bddd7a8d | 375 | WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename); |
c801d85f KB |
376 | |
377 | // Get filename | |
bddd7a8d VZ |
378 | WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path); |
379 | WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path); | |
c801d85f KB |
380 | |
381 | // Get directory | |
bddd7a8d | 382 | WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path); |
c801d85f KB |
383 | |
384 | // wxString version | |
bddd7a8d | 385 | WXDLLIMPEXP_BASE wxString wxRealPath(const wxString& path); |
c801d85f | 386 | |
bddd7a8d | 387 | WXDLLIMPEXP_BASE void wxDos2UnixFilename(wxChar *s); |
c801d85f | 388 | |
bddd7a8d | 389 | WXDLLIMPEXP_BASE void wxUnix2DosFilename(wxChar *s); |
c801d85f KB |
390 | |
391 | // Strip the extension, in situ | |
bddd7a8d VZ |
392 | WXDLLIMPEXP_BASE void wxStripExtension(wxChar *buffer); |
393 | WXDLLIMPEXP_BASE void wxStripExtension(wxString& buffer); | |
c801d85f | 394 | |
ade35f11 | 395 | // Get a temporary filename |
bddd7a8d VZ |
396 | WXDLLIMPEXP_BASE wxChar* wxGetTempFileName(const wxString& prefix, wxChar *buf = (wxChar *) NULL); |
397 | WXDLLIMPEXP_BASE bool wxGetTempFileName(const wxString& prefix, wxString& buf); | |
c801d85f KB |
398 | |
399 | // Expand file name (~/ and ${OPENWINHOME}/ stuff) | |
bddd7a8d VZ |
400 | WXDLLIMPEXP_BASE wxChar* wxExpandPath(wxChar *dest, const wxChar *path); |
401 | WXDLLIMPEXP_BASE bool wxExpandPath(wxString& dest, const wxChar *path); | |
c801d85f KB |
402 | |
403 | // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib) | |
404 | // and make (if under the home tree) relative to home | |
405 | // [caller must copy-- volatile] | |
bddd7a8d | 406 | WXDLLIMPEXP_BASE wxChar* wxContractPath(const wxString& filename, |
ade35f11 VZ |
407 | const wxString& envname = wxEmptyString, |
408 | const wxString& user = wxEmptyString); | |
c801d85f KB |
409 | |
410 | // Destructive removal of /./ and /../ stuff | |
bddd7a8d | 411 | WXDLLIMPEXP_BASE wxChar* wxRealPath(wxChar *path); |
c801d85f KB |
412 | |
413 | // Allocate a copy of the full absolute path | |
bddd7a8d | 414 | WXDLLIMPEXP_BASE wxChar* wxCopyAbsolutePath(const wxString& path); |
c801d85f KB |
415 | |
416 | // Get first file name matching given wild card. | |
417 | // Flags are reserved for future use. | |
418 | #define wxFILE 1 | |
419 | #define wxDIR 2 | |
bddd7a8d VZ |
420 | WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxChar *spec, int flags = wxFILE); |
421 | WXDLLIMPEXP_BASE wxString wxFindNextFile(); | |
c801d85f KB |
422 | |
423 | // Does the pattern contain wildcards? | |
bddd7a8d | 424 | WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern); |
c801d85f KB |
425 | |
426 | // Does the pattern match the text (usually a filename)? | |
a62848fd | 427 | // If dot_special is true, doesn't match * against . (eliminating |
c801d85f | 428 | // `hidden' dot files) |
a62848fd | 429 | WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = true); |
c801d85f KB |
430 | |
431 | // Concatenate two files to form third | |
bddd7a8d | 432 | WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3); |
c801d85f KB |
433 | |
434 | // Copy file1 to file2 | |
bddd7a8d | 435 | WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& file1, const wxString& file2, |
a62848fd | 436 | bool overwrite = true); |
c801d85f KB |
437 | |
438 | // Remove file | |
bddd7a8d | 439 | WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file); |
c801d85f KB |
440 | |
441 | // Rename file | |
bddd7a8d | 442 | WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& file1, const wxString& file2); |
c801d85f KB |
443 | |
444 | // Get current working directory. | |
445 | // If buf is NULL, allocates space using new, else | |
446 | // copies into buf. | |
447 | // IMPORTANT NOTE getcwd is know not to work under some releases | |
448 | // of Win32s 1.3, according to MS release notes! | |
bddd7a8d | 449 | WXDLLIMPEXP_BASE wxChar* wxGetWorkingDirectory(wxChar *buf = (wxChar *) NULL, int sz = 1000); |
7af89395 VZ |
450 | // new and preferred version of wxGetWorkingDirectory |
451 | // NB: can't have the same name because of overloading ambiguity | |
bddd7a8d | 452 | WXDLLIMPEXP_BASE wxString wxGetCwd(); |
c801d85f KB |
453 | |
454 | // Set working directory | |
bddd7a8d | 455 | WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d); |
c801d85f KB |
456 | |
457 | // Make directory | |
bddd7a8d | 458 | WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = 0777); |
c801d85f KB |
459 | |
460 | // Remove directory. Flags reserved for future use. | |
bddd7a8d | 461 | WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0); |
c801d85f | 462 | |
3c70014d | 463 | // Return the type of an open file |
0912690b | 464 | WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd); |
9802983f | 465 | WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp); |
3c70014d | 466 | |
2b5f62a0 | 467 | // compatibility defines, don't use in new code |
da865fdd WS |
468 | // consider removal droping 2.4 compatibility |
469 | // #if WXWIN_COMPATIBILITY_2_4 | |
470 | wxDEPRECATED( inline bool wxPathExists(const wxChar *pszPathName) ); | |
471 | inline bool wxPathExists(const wxChar *pszPathName) | |
472 | { | |
473 | return wxDirExists(pszPathName); | |
474 | } | |
475 | // #endif //WXWIN_COMPATIBILITY_2_4 | |
2b5f62a0 | 476 | |
ff69a290 | 477 | // ---------------------------------------------------------------------------- |
c801d85f | 478 | // separators in file names |
ff69a290 VZ |
479 | // ---------------------------------------------------------------------------- |
480 | ||
481 | // between file name and extension | |
223d09f6 | 482 | #define wxFILE_SEP_EXT wxT('.') |
ff69a290 VZ |
483 | |
484 | // between drive/volume name and the path | |
223d09f6 | 485 | #define wxFILE_SEP_DSK wxT(':') |
ff69a290 VZ |
486 | |
487 | // between the path components | |
223d09f6 KB |
488 | #define wxFILE_SEP_PATH_DOS wxT('\\') |
489 | #define wxFILE_SEP_PATH_UNIX wxT('/') | |
844f90fb | 490 | #define wxFILE_SEP_PATH_MAC wxT(':') |
ff69a290 | 491 | #define wxFILE_SEP_PATH_VMS wxT('.') // VMS also uses '[' and ']' |
c801d85f KB |
492 | |
493 | // separator in the path list (as in PATH environment variable) | |
03e11df5 GD |
494 | // there is no PATH variable in Classic Mac OS so just use the |
495 | // semicolon (it must be different from the file name separator) | |
c801d85f | 496 | // NB: these are strings and not characters on purpose! |
223d09f6 KB |
497 | #define wxPATH_SEP_DOS wxT(";") |
498 | #define wxPATH_SEP_UNIX wxT(":") | |
03e11df5 | 499 | #define wxPATH_SEP_MAC wxT(";") |
c801d85f KB |
500 | |
501 | // platform independent versions | |
77a80672 VZ |
502 | #if defined(__UNIX__) && !defined(__OS2__) |
503 | // CYGWIN also uses UNIX settings | |
7af89395 VZ |
504 | #define wxFILE_SEP_PATH wxFILE_SEP_PATH_UNIX |
505 | #define wxPATH_SEP wxPATH_SEP_UNIX | |
844f90fb | 506 | #elif defined(__MAC__) |
bedaf53e | 507 | #define wxFILE_SEP_PATH wxFILE_SEP_PATH_MAC |
3369df87 | 508 | #define wxPATH_SEP wxPATH_SEP_MAC |
1777b9bb | 509 | #else // Windows and OS/2 |
7af89395 VZ |
510 | #define wxFILE_SEP_PATH wxFILE_SEP_PATH_DOS |
511 | #define wxPATH_SEP wxPATH_SEP_DOS | |
c801d85f KB |
512 | #endif // Unix/Windows |
513 | ||
92abb45d VZ |
514 | // this is useful for wxString::IsSameAs(): to compare two file names use |
515 | // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE) | |
28e5e577 | 516 | #if defined(__UNIX__) && !defined(__DARWIN__) && !defined(__OS2__) |
a62848fd | 517 | #define wxARE_FILENAMES_CASE_SENSITIVE true |
3369df87 | 518 | #else // Windows, Mac OS and OS/2 |
a62848fd | 519 | #define wxARE_FILENAMES_CASE_SENSITIVE false |
92abb45d VZ |
520 | #endif // Unix/Windows |
521 | ||
c801d85f | 522 | // is the char a path separator? |
9d2f3c71 | 523 | inline bool wxIsPathSeparator(wxChar c) |
903b61cc VZ |
524 | { |
525 | // under DOS/Windows we should understand both Unix and DOS file separators | |
a62848fd | 526 | #if ( defined(__UNIX__) && !defined(__OS2__) )|| defined(__MAC__) |
903b61cc VZ |
527 | return c == wxFILE_SEP_PATH; |
528 | #else | |
529 | return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX; | |
530 | #endif | |
531 | } | |
c801d85f KB |
532 | |
533 | // does the string ends with path separator? | |
bddd7a8d | 534 | WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxChar *pszFileName); |
c801d85f | 535 | |
92abb45d VZ |
536 | // split the full path into path (including drive for DOS), name and extension |
537 | // (understands both '/' and '\\') | |
bddd7a8d | 538 | WXDLLIMPEXP_BASE void wxSplitPath(const wxChar *pszFileName, |
92abb45d VZ |
539 | wxString *pstrPath, |
540 | wxString *pstrName, | |
541 | wxString *pstrExt); | |
542 | ||
c801d85f | 543 | // find a file in a list of directories, returns false if not found |
bddd7a8d | 544 | WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxChar *pszPath, const wxChar *pszFile); |
c801d85f | 545 | |
631f1bfe JS |
546 | // Get the OS directory if appropriate (such as the Windows directory). |
547 | // On non-Windows platform, probably just return the empty string. | |
bddd7a8d | 548 | WXDLLIMPEXP_BASE wxString wxGetOSDirectory(); |
631f1bfe | 549 | |
a47ce4a7 | 550 | // Get file modification time |
bddd7a8d | 551 | WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename); |
a47ce4a7 | 552 | |
9e152a55 WS |
553 | // Parses the wildCard, returning the number of filters. |
554 | // Returns 0 if none or if there's a problem, | |
555 | // The arrays will contain an equal number of items found before the error. | |
556 | // wildCard is in the form: | |
557 | // "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png" | |
daf32463 | 558 | WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters); |
9e152a55 | 559 | |
45ea509a VZ |
560 | // ---------------------------------------------------------------------------- |
561 | // classes | |
562 | // ---------------------------------------------------------------------------- | |
563 | ||
8482e4bd VZ |
564 | #ifdef __UNIX__ |
565 | ||
566 | // set umask to the given value in ctor and reset it to the old one in dtor | |
567 | class WXDLLIMPEXP_BASE wxUmaskChanger | |
568 | { | |
569 | public: | |
570 | // change the umask to the given one if it is not -1: this allows to write | |
571 | // the same code whether you really want to change umask or not, as is in | |
572 | // wxFileConfig::Flush() for example | |
573 | wxUmaskChanger(int umaskNew) | |
574 | { | |
835fab50 | 575 | m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew); |
8482e4bd VZ |
576 | } |
577 | ||
578 | ~wxUmaskChanger() | |
579 | { | |
580 | if ( m_umaskOld != -1 ) | |
581 | umask((mode_t)m_umaskOld); | |
582 | } | |
583 | ||
584 | private: | |
585 | int m_umaskOld; | |
586 | }; | |
587 | ||
588 | // this macro expands to an "anonymous" wxUmaskChanger object under Unix and | |
589 | // nothing elsewhere | |
590 | #define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m) | |
591 | ||
592 | #else // !__UNIX__ | |
593 | ||
594 | #define wxCHANGE_UMASK(m) | |
595 | ||
596 | #endif // __UNIX__/!__UNIX__ | |
597 | ||
598 | ||
c801d85f | 599 | // Path searching |
bddd7a8d | 600 | class WXDLLIMPEXP_BASE wxPathList : public wxStringList |
c801d85f | 601 | { |
a6f6393c | 602 | public: |
df5168c4 MB |
603 | // avoid GCC warning about virtual functions w/o virtual dtor |
604 | virtual ~wxPathList() {} | |
605 | ||
7af89395 VZ |
606 | // Adds all paths in environment variable |
607 | void AddEnvList(const wxString& envVariable); | |
c330a2cf | 608 | |
a6f6393c | 609 | void Add(const wxString& path); |
7af89395 VZ |
610 | // Find the first full path for which the file exists |
611 | wxString FindValidPath(const wxString& filename); | |
612 | // Find the first full path for which the file exists; ensure it's an | |
613 | // absolute path that gets returned. | |
614 | wxString FindAbsoluteValidPath(const wxString& filename); | |
615 | // Given full path and filename, add path to list | |
616 | void EnsureFileAccessible(const wxString& path); | |
a62848fd | 617 | // Returns true if the path is in the list |
a6f6393c VZ |
618 | bool Member(const wxString& path); |
619 | ||
620 | private: | |
df5168c4 | 621 | // DECLARE_DYNAMIC_CLASS(wxPathList) |
c801d85f KB |
622 | }; |
623 | ||
624 | #endif | |
34138703 | 625 | // _WX_FILEFN_H_ |