Coverage Report

Created: 2023-02-22 06:06

/src/wxwidgets/include/wx/filefn.h
Line
Count
Source (jump to first uncovered line)
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
// Copyright:   (c) 1998 Julian Smart
8
// Licence:     wxWindows licence
9
/////////////////////////////////////////////////////////////////////////////
10
11
#ifndef   _FILEFN_H_
12
#define   _FILEFN_H_
13
14
#include "wx/list.h"
15
#include "wx/arrstr.h"
16
17
#include <time.h>
18
19
#include <sys/types.h>
20
#include <sys/stat.h>
21
22
#if defined(__UNIX__)
23
    #include <unistd.h>
24
    #include <dirent.h>
25
#endif
26
27
#if defined(__WINDOWS__)
28
#if !defined( __GNUWIN32__ ) && !defined(__CYGWIN__)
29
    #include <direct.h>
30
    #include <dos.h>
31
    #include <io.h>
32
#endif // __WINDOWS__
33
#endif // native Win compiler
34
35
#include  <fcntl.h>       // O_RDONLY &c
36
37
// ----------------------------------------------------------------------------
38
// constants
39
// ----------------------------------------------------------------------------
40
41
// MSVC doesn't define mode_t, so do it ourselves unless someone else
42
// had already predefined it.
43
#if defined(__VISUALC__) && !defined(wxHAS_MODE_T)
44
    #define wxHAS_MODE_T
45
    typedef int mode_t;
46
#endif
47
48
// define off_t
49
#include  <sys/types.h>
50
51
#if defined(__VISUALC__)
52
    typedef _off_t off_t;
53
#endif
54
55
enum wxSeekMode
56
{
57
  wxFromStart,
58
  wxFromCurrent,
59
  wxFromEnd
60
};
61
62
enum wxFileKind
63
{
64
  wxFILE_KIND_UNKNOWN,
65
  wxFILE_KIND_DISK,     // a file supporting seeking to arbitrary offsets
66
  wxFILE_KIND_TERMINAL, // a tty
67
  wxFILE_KIND_PIPE      // a pipe
68
};
69
70
// we redefine these constants here because S_IREAD &c are _not_ standard
71
// however, we do assume that the values correspond to the Unix umask bits
72
enum wxPosixPermissions
73
{
74
    // standard Posix names for these permission flags:
75
    wxS_IRUSR = 00400,
76
    wxS_IWUSR = 00200,
77
    wxS_IXUSR = 00100,
78
79
    wxS_IRGRP = 00040,
80
    wxS_IWGRP = 00020,
81
    wxS_IXGRP = 00010,
82
83
    wxS_IROTH = 00004,
84
    wxS_IWOTH = 00002,
85
    wxS_IXOTH = 00001,
86
87
    // longer but more readable synonyms for the constants above:
88
    wxPOSIX_USER_READ = wxS_IRUSR,
89
    wxPOSIX_USER_WRITE = wxS_IWUSR,
90
    wxPOSIX_USER_EXECUTE = wxS_IXUSR,
91
92
    wxPOSIX_GROUP_READ = wxS_IRGRP,
93
    wxPOSIX_GROUP_WRITE = wxS_IWGRP,
94
    wxPOSIX_GROUP_EXECUTE = wxS_IXGRP,
95
96
    wxPOSIX_OTHERS_READ = wxS_IROTH,
97
    wxPOSIX_OTHERS_WRITE = wxS_IWOTH,
98
    wxPOSIX_OTHERS_EXECUTE = wxS_IXOTH,
99
100
    // default mode for the new files: allow reading/writing them to everybody but
101
    // the effective file mode will be set after anding this value with umask and
102
    // so won't include wxS_IW{GRP,OTH} for the default 022 umask value
103
    wxS_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | \
104
                   wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | \
105
                   wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE),
106
107
    // default mode for the new directories (see wxFileName::Mkdir): allow
108
    // reading/writing/executing them to everybody, but just like wxS_DEFAULT
109
    // the effective directory mode will be set after anding this value with umask
110
    wxS_DIR_DEFAULT = (wxPOSIX_USER_READ | wxPOSIX_USER_WRITE | wxPOSIX_USER_EXECUTE | \
111
                       wxPOSIX_GROUP_READ | wxPOSIX_GROUP_WRITE | wxPOSIX_GROUP_EXECUTE | \
112
                       wxPOSIX_OTHERS_READ | wxPOSIX_OTHERS_WRITE | wxPOSIX_OTHERS_EXECUTE)
113
};
114
115
// ----------------------------------------------------------------------------
116
// declare our versions of low level file functions: some compilers prepend
117
// underscores to the usual names, some also have Unicode versions of them
118
// ----------------------------------------------------------------------------
119
120
#if defined(__WINDOWS__) && \
121
      ( \
122
        defined(__VISUALC__) || \
123
        defined(__MINGW64_TOOLCHAIN__) || \
124
        (defined(__MINGW32__) && !defined(__WINE__)) \
125
      )
126
127
    // temporary defines just used immediately below
128
    #undef wxHAS_HUGE_FILES
129
    #undef wxHAS_HUGE_STDIO_FILES
130
131
    // detect compilers which have support for huge files
132
    #if defined(__VISUALC__)
133
        #define wxHAS_HUGE_FILES 1
134
    #elif defined(__MINGW32__)
135
        #define wxHAS_HUGE_FILES 1
136
    #elif defined(_LARGE_FILES)
137
        #define wxHAS_HUGE_FILES 1
138
    #endif
139
140
    // detect compilers which have support for huge stdio files
141
    #if defined(__VISUALC__)
142
        #define wxHAS_HUGE_STDIO_FILES
143
        #define wxFseek _fseeki64
144
        #define wxFtell _ftelli64
145
    #elif wxCHECK_MINGW32_VERSION(3, 5) // mingw-runtime version (not gcc)
146
        #define wxHAS_HUGE_STDIO_FILES
147
148
        wxDECL_FOR_STRICT_MINGW32(int, fseeko64, (FILE*, long long, int))
149
        #define wxFseek fseeko64
150
151
        #ifdef wxNEEDS_STRICT_ANSI_WORKAROUNDS
152
            // Unfortunately ftello64() is not defined in the library for
153
            // whatever reason but as an inline function, so define wxFtell()
154
            // here similarly.
155
            inline long long wxFtell(FILE* fp)
156
            {
157
                fpos_t pos;
158
                if ( fgetpos(fp, &pos) != 0 )
159
                    return -1LL;
160
161
                // Unfortunately our interface assumes that the file position
162
                // is representable as "long long", so we have to get it from
163
                // fpos_t, even though it's an opaque type. And its exact
164
                // representation has changed in MinGW, so we have to test for
165
                // mingwrt version.
166
                #if wxCHECK_MINGW32_VERSION(5, 2)
167
                    // In 5.2.2 it's a union with a __value field.
168
                    return pos.__value;
169
                #else
170
                    // Up to 5.1.1 it was a simple typedef.
171
                    return pos;
172
                #endif
173
            }
174
        #else
175
            #define wxFtell ftello64
176
        #endif
177
    #endif
178
179
180
    // types
181
182
    #ifdef wxHAS_HUGE_FILES
183
        typedef wxLongLong_t wxFileOffset;
184
        #define wxFileOffsetFmtSpec wxLongLongFmtSpec
185
    #else
186
        typedef off_t wxFileOffset;
187
    #endif
188
189
190
    #define wxPOSIX_STRUCT(s) struct wxPOSIX_IDENT(s)
191
192
    #ifdef wxHAS_HUGE_FILES
193
        #define wxStructStat struct _stati64
194
    #else
195
        #define wxStructStat struct _stat
196
    #endif
197
198
199
    // functions
200
201
    // MSVC and compatible compilers prepend underscores to the POSIX function
202
    // names, other compilers don't and even if their later versions usually do
203
    // define the versions with underscores for MSVC compatibility, it's better
204
    // to avoid using them as they're not present in earlier versions and
205
    // always using the native functions spelling is easier than testing for
206
    // the versions
207
    #if defined(__MINGW64_TOOLCHAIN__)
208
        #define wxPOSIX_IDENT(func)    ::func
209
    #else // by default assume MSVC-compatible names
210
        #define wxPOSIX_IDENT(func)    _ ## func
211
        #define wxHAS_UNDERSCORES_IN_POSIX_IDENTS
212
    #endif
213
214
    // first functions not working with strings, i.e. without ANSI/Unicode
215
    // complications
216
    #define   wxClose      wxPOSIX_IDENT(close)
217
218
    #define wxRead         wxPOSIX_IDENT(read)
219
    #define wxWrite        wxPOSIX_IDENT(write)
220
221
    #ifdef wxHAS_HUGE_FILES
222
        #ifndef __MINGW64_TOOLCHAIN__
223
            #define   wxSeek       wxPOSIX_IDENT(lseeki64)
224
            #define   wxLseek      wxPOSIX_IDENT(lseeki64)
225
            #define   wxTell       wxPOSIX_IDENT(telli64)
226
        #else
227
            // unfortunately, mingw-W64 is somewhat inconsistent...
228
            #define   wxSeek       _lseeki64
229
            #define   wxLseek      _lseeki64
230
            #define   wxTell       _telli64
231
        #endif
232
    #else // !wxHAS_HUGE_FILES
233
        #define   wxSeek       wxPOSIX_IDENT(lseek)
234
        #define   wxLseek      wxPOSIX_IDENT(lseek)
235
        #define   wxTell       wxPOSIX_IDENT(tell)
236
    #endif // wxHAS_HUGE_FILES/!wxHAS_HUGE_FILES
237
238
239
     #define   wxFsync      _commit
240
241
     // could be already defined by configure (Cygwin)
242
     #ifndef HAVE_FSYNC
243
         #define HAVE_FSYNC
244
     #endif
245
246
    #define   wxEof        wxPOSIX_IDENT(eof)
247
248
    // then the functions taking strings
249
    #define wxCRT_Open          _wopen
250
251
    wxDECL_FOR_STRICT_MINGW32(int, _wopen, (const wchar_t*, int, ...))
252
    wxDECL_FOR_STRICT_MINGW32(int, _waccess, (const wchar_t*, int))
253
    wxDECL_FOR_STRICT_MINGW32(int, _wchmod, (const wchar_t*, int))
254
    wxDECL_FOR_STRICT_MINGW32(int, _wmkdir, (const wchar_t*))
255
    wxDECL_FOR_STRICT_MINGW32(int, _wrmdir, (const wchar_t*))
256
    wxDECL_FOR_STRICT_MINGW32(int, _wstati64, (const wchar_t*, struct _stati64*))
257
258
    #define   wxCRT_Access      _waccess
259
    #define   wxCRT_Chmod       _wchmod
260
    #define   wxCRT_MkDir       _wmkdir
261
    #define   wxCRT_RmDir       _wrmdir
262
    #ifdef wxHAS_HUGE_FILES
263
        #define   wxCRT_Stat        _wstati64
264
    #else
265
        #define   wxCRT_Stat        _wstat
266
    #endif
267
268
269
    // constants (unless already defined by the user code)
270
    #ifdef wxHAS_UNDERSCORES_IN_POSIX_IDENTS
271
        #ifndef O_RDONLY
272
            #define   O_RDONLY    _O_RDONLY
273
            #define   O_WRONLY    _O_WRONLY
274
            #define   O_RDWR      _O_RDWR
275
            #define   O_EXCL      _O_EXCL
276
            #define   O_CREAT     _O_CREAT
277
            #define   O_BINARY    _O_BINARY
278
        #endif
279
280
        #ifndef S_IFMT
281
            #define   S_IFMT      _S_IFMT
282
            #define   S_IFDIR     _S_IFDIR
283
            #define   S_IFREG     _S_IFREG
284
        #endif
285
    #endif // wxHAS_UNDERSCORES_IN_POSIX_IDENTS
286
287
    #ifdef wxHAS_HUGE_FILES
288
        // wxFile is present and supports large files.
289
        #if wxUSE_FILE
290
            #define wxHAS_LARGE_FILES
291
        #endif
292
        // wxFFile is present and supports large files
293
        #if wxUSE_FFILE && defined wxHAS_HUGE_STDIO_FILES
294
            #define wxHAS_LARGE_FFILES
295
        #endif
296
    #endif
297
298
    // private defines, undefine so that nobody gets tempted to use
299
    #undef wxHAS_HUGE_FILES
300
    #undef wxHAS_HUGE_STDIO_FILES
301
#else // Unix or Windows using unknown compiler, assume POSIX supported
302
    typedef off_t wxFileOffset;
303
    #ifdef HAVE_LARGEFILE_SUPPORT
304
        #define wxFileOffsetFmtSpec wxLongLongFmtSpec
305
        wxCOMPILE_TIME_ASSERT( sizeof(off_t) == sizeof(wxLongLong_t),
306
                                BadFileSizeType );
307
        // wxFile is present and supports large files
308
        #if wxUSE_FILE
309
            #define wxHAS_LARGE_FILES
310
        #endif
311
        // wxFFile is present and supports large files
312
        #if wxUSE_FFILE && (SIZEOF_LONG == 8 || defined HAVE_FSEEKO)
313
            #define wxHAS_LARGE_FFILES
314
        #endif
315
        #ifdef HAVE_FSEEKO
316
0
            #define wxFseek fseeko
317
0
            #define wxFtell ftello
318
        #endif
319
    #else
320
        #define wxFileOffsetFmtSpec wxT("")
321
    #endif
322
    // functions
323
0
    #define   wxClose      close
324
0
    #define   wxRead       ::read
325
0
    #define   wxWrite      ::write
326
    #define   wxLseek      lseek
327
0
    #define   wxSeek       lseek
328
0
    #define   wxFsync      fsync
329
    #define   wxEof        eof
330
    #define   wxCRT_MkDir      mkdir
331
0
    #define   wxCRT_RmDir      rmdir
332
333
0
    #define   wxTell(fd)   lseek(fd, 0, SEEK_CUR)
334
335
0
    #define   wxStructStat struct stat
336
337
0
    #define   wxCRT_Open       open
338
0
    #define   wxCRT_Stat       stat
339
0
    #define   wxCRT_Lstat      lstat
340
0
    #define   wxCRT_Access     access
341
0
    #define   wxCRT_Chmod      chmod
342
343
0
    #define   wxCRT_Readlink   readlink
344
345
    #define wxHAS_NATIVE_LSTAT
346
    #define wxHAS_NATIVE_READLINK
347
#endif // platforms
348
349
// if the platform doesn't have symlinks, define wxCRT_Lstat to be the same as
350
// wxCRT_Stat to avoid #ifdefs in the code using it
351
#ifndef wxHAS_NATIVE_LSTAT
352
    #define wxCRT_Lstat wxCRT_Stat
353
#endif
354
355
// define wxFseek/wxFtell to large file versions if available (done above) or
356
// to fseek/ftell if not, to save ifdefs in using code
357
#ifndef wxFseek
358
    #define wxFseek fseek
359
#endif
360
#ifndef wxFtell
361
    #define wxFtell ftell
362
#endif
363
364
inline int wxAccess(const wxString& path, mode_t mode)
365
0
    { return wxCRT_Access(path.fn_str(), mode); }
366
inline int wxChmod(const wxString& path, mode_t mode)
367
0
    { return wxCRT_Chmod(path.fn_str(), mode); }
368
inline int wxOpen(const wxString& path, int flags, mode_t mode)
369
0
    { return wxCRT_Open(path.fn_str(), flags, mode); }
370
371
#if defined(wxHAS_NATIVE_READLINK)
372
inline ssize_t wxReadlink(const wxString& path, char* buf, int size)
373
0
    { return wxCRT_Readlink(path.fn_str(), buf, size); }
374
#endif
375
376
inline int wxStat(const wxString& path, wxStructStat *buf)
377
0
    { return wxCRT_Stat(path.fn_str(), buf); }
378
inline int wxLstat(const wxString& path, wxStructStat *buf)
379
0
    { return wxCRT_Lstat(path.fn_str(), buf); }
380
inline int wxRmDir(const wxString& path)
381
0
    { return wxCRT_RmDir(path.fn_str()); }
382
#if (defined(__WINDOWS__) && !defined(__CYGWIN__))
383
inline int wxMkDir(const wxString& path, mode_t WXUNUSED(mode) = 0)
384
    { return wxCRT_MkDir(path.fn_str()); }
385
#else
386
inline int wxMkDir(const wxString& path, mode_t mode)
387
0
    { return wxCRT_MkDir(path.fn_str(), mode); }
388
#endif
389
390
#ifdef O_BINARY
391
    #define wxO_BINARY O_BINARY
392
#else
393
0
    #define wxO_BINARY 0
394
#endif
395
396
const int wxInvalidOffset = -1;
397
398
// ----------------------------------------------------------------------------
399
// functions
400
// ----------------------------------------------------------------------------
401
WXDLLIMPEXP_BASE bool wxFileExists(const wxString& filename);
402
403
// does the path exist? (may have or not '/' or '\\' at the end)
404
WXDLLIMPEXP_BASE bool wxDirExists(const wxString& pathName);
405
406
WXDLLIMPEXP_BASE bool wxIsAbsolutePath(const wxString& filename);
407
408
// Get filename
409
WXDLLIMPEXP_BASE wxChar* wxFileNameFromPath(wxChar *path);
410
WXDLLIMPEXP_BASE wxString wxFileNameFromPath(const wxString& path);
411
412
// Get directory
413
WXDLLIMPEXP_BASE wxString wxPathOnly(const wxString& path);
414
415
// Get first file name matching given wild card.
416
// Flags are reserved for future use.
417
0
#define wxFILE  1
418
0
#define wxDIR   2
419
WXDLLIMPEXP_BASE wxString wxFindFirstFile(const wxString& spec, int flags = wxFILE);
420
WXDLLIMPEXP_BASE wxString wxFindNextFile();
421
422
// Does the pattern contain wildcards?
423
WXDLLIMPEXP_BASE bool wxIsWild(const wxString& pattern);
424
425
// Does the pattern match the text (usually a filename)?
426
// If dot_special is true, doesn't match * against . (eliminating
427
// `hidden' dot files)
428
WXDLLIMPEXP_BASE bool wxMatchWild(const wxString& pattern,  const wxString& text, bool dot_special = true);
429
430
// Concatenate two files to form third
431
WXDLLIMPEXP_BASE bool wxConcatFiles(const wxString& src1, const wxString& src2, const wxString& dest);
432
433
// Copy file
434
WXDLLIMPEXP_BASE bool wxCopyFile(const wxString& src, const wxString& dest,
435
                                 bool overwrite = true);
436
437
// Remove file
438
WXDLLIMPEXP_BASE bool wxRemoveFile(const wxString& file);
439
440
// Rename file
441
WXDLLIMPEXP_BASE bool wxRenameFile(const wxString& oldpath, const wxString& newpath, bool overwrite = true);
442
443
// Get current working directory.
444
WXDLLIMPEXP_BASE wxString wxGetCwd();
445
446
// Set working directory
447
WXDLLIMPEXP_BASE bool wxSetWorkingDirectory(const wxString& d);
448
449
// Make directory
450
WXDLLIMPEXP_BASE bool wxMkdir(const wxString& dir, int perm = wxS_DIR_DEFAULT);
451
452
// Remove directory. Flags reserved for future use.
453
WXDLLIMPEXP_BASE bool wxRmdir(const wxString& dir, int flags = 0);
454
455
// Return the type of an open file
456
WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(int fd);
457
WXDLLIMPEXP_BASE wxFileKind wxGetFileKind(FILE *fp);
458
459
// permissions; these functions work both on files and directories:
460
WXDLLIMPEXP_BASE bool wxIsWritable(const wxString &path);
461
WXDLLIMPEXP_BASE bool wxIsReadable(const wxString &path);
462
WXDLLIMPEXP_BASE bool wxIsExecutable(const wxString &path);
463
464
// ----------------------------------------------------------------------------
465
// separators in file names
466
// ----------------------------------------------------------------------------
467
468
// between file name and extension
469
0
#define wxFILE_SEP_EXT        wxT('.')
470
471
// between drive/volume name and the path
472
0
#define wxFILE_SEP_DSK        wxT(':')
473
474
// between the path components
475
52.5k
#define wxFILE_SEP_PATH_DOS   wxT('\\')
476
50.1k
#define wxFILE_SEP_PATH_UNIX  wxT('/')
477
0
#define wxFILE_SEP_PATH_MAC   wxT(':')
478
0
#define wxFILE_SEP_PATH_VMS   wxT('.') // VMS also uses '[' and ']'
479
480
// separator in the path list (as in PATH environment variable)
481
// there is no PATH variable in Classic Mac OS so just use the
482
// semicolon (it must be different from the file name separator)
483
// NB: these are strings and not characters on purpose!
484
#define wxPATH_SEP_DOS        wxT(";")
485
0
#define wxPATH_SEP_UNIX       wxT(":")
486
#define wxPATH_SEP_MAC        wxT(";")
487
488
// platform independent versions
489
#if defined(__UNIX__)
490
  // CYGWIN also uses UNIX settings
491
0
  #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_UNIX
492
0
  #define wxPATH_SEP          wxPATH_SEP_UNIX
493
#elif defined(__MAC__)
494
  #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_MAC
495
  #define wxPATH_SEP          wxPATH_SEP_MAC
496
#else   // Windows
497
  #define wxFILE_SEP_PATH     wxFILE_SEP_PATH_DOS
498
  #define wxPATH_SEP          wxPATH_SEP_DOS
499
#endif  // Unix/Windows
500
501
// this is useful for wxString::IsSameAs(): to compare two file names use
502
// filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE)
503
#if defined(__UNIX__) && !defined(__DARWIN__)
504
  #define wxARE_FILENAMES_CASE_SENSITIVE  true
505
#else   // Windows and OSX
506
  #define wxARE_FILENAMES_CASE_SENSITIVE  false
507
#endif  // Unix/Windows
508
509
// is the char a path separator?
510
inline bool wxIsPathSeparator(wxChar c)
511
0
{
512
    // under DOS/Windows we should understand both Unix and DOS file separators
513
0
#if defined(__UNIX__) || defined(__MAC__)
514
0
    return c == wxFILE_SEP_PATH;
515
#else
516
    return c == wxFILE_SEP_PATH_DOS || c == wxFILE_SEP_PATH_UNIX;
517
#endif
518
0
}
519
520
// does the string ends with path separator?
521
WXDLLIMPEXP_BASE bool wxEndsWithPathSeparator(const wxString& filename);
522
523
// find a file in a list of directories, returns false if not found
524
WXDLLIMPEXP_BASE bool wxFindFileInPath(wxString *pStr, const wxString& szPath, const wxString& szFile);
525
526
// Get the OS directory if appropriate (such as the Windows directory).
527
// On non-Windows platform, probably just return the empty string.
528
WXDLLIMPEXP_BASE wxString wxGetOSDirectory();
529
530
#if wxUSE_DATETIME
531
532
// Get file modification time
533
WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename);
534
535
#endif // wxUSE_DATETIME
536
537
// Parses the wildCard, returning the number of filters.
538
// Returns 0 if none or if there's a problem,
539
// The arrays will contain an equal number of items found before the error.
540
// wildCard is in the form:
541
// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png"
542
WXDLLIMPEXP_BASE int wxParseCommonDialogsFilter(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters);
543
544
// ----------------------------------------------------------------------------
545
// classes
546
// ----------------------------------------------------------------------------
547
548
#ifdef __UNIX__
549
550
// set umask to the given value in ctor and reset it to the old one in dtor
551
class WXDLLIMPEXP_BASE wxUmaskChanger
552
{
553
public:
554
    // change the umask to the given one if it is not -1: this allows to write
555
    // the same code whether you really want to change umask or not, as is in
556
    // wxFileConfig::Flush() for example
557
    wxUmaskChanger(int umaskNew)
558
0
    {
559
0
        m_umaskOld = umaskNew == -1 ? -1 : (int)umask((mode_t)umaskNew);
560
0
    }
561
562
    ~wxUmaskChanger()
563
0
    {
564
0
        if ( m_umaskOld != -1 )
565
0
            umask((mode_t)m_umaskOld);
566
0
    }
567
568
private:
569
    int m_umaskOld;
570
};
571
572
// this macro expands to an "anonymous" wxUmaskChanger object under Unix and
573
// nothing elsewhere
574
0
#define wxCHANGE_UMASK(m) wxUmaskChanger wxMAKE_UNIQUE_NAME(umaskChanger_)(m)
575
576
#else // !__UNIX__
577
578
#define wxCHANGE_UMASK(m)
579
580
#endif // __UNIX__/!__UNIX__
581
582
583
// Path searching
584
class WXDLLIMPEXP_BASE wxPathList : public wxArrayString
585
{
586
public:
587
0
    wxPathList() {}
588
    wxPathList(const wxArrayString &arr)
589
0
        { Add(arr); }
590
591
    // Adds all paths in environment variable
592
    void AddEnvList(const wxString& envVariable);
593
594
    // Adds given path to this list
595
    bool Add(const wxString& path);
596
    void Add(const wxArrayString &paths);
597
598
    // Find the first full path for which the file exists
599
    wxString FindValidPath(const wxString& filename) const;
600
601
    // Find the first full path for which the file exists; ensure it's an
602
    // absolute path that gets returned.
603
    wxString FindAbsoluteValidPath(const wxString& filename) const;
604
605
    // Given full path and filename, add path to list
606
    bool EnsureFileAccessible(const wxString& path);
607
};
608
609
#endif // _WX_FILEFN_H_