1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/filefn.cpp
3 // Purpose: File- and directory-related functions
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/filefn.h"
36 #include "wx/dynarray.h"
38 #include "wx/filename.h"
41 #include "wx/tokenzr.h"
43 // there are just too many of those...
45 #pragma warning(disable:4706) // assignment within conditional expression
52 #if !wxONLY_WATCOM_EARLIER_THAN(1,4)
53 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
58 #if defined(__WXMAC__)
59 #include "wx/osx/private.h" // includes mac headers
63 #include "wx/msw/private.h"
64 #include "wx/msw/mslu.h"
66 // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
68 // note that it must be included after <windows.h>
71 #include <sys/cygwin.h>
73 #endif // __GNUWIN32__
75 // io.h is needed for _get_osfhandle()
76 // Already included by filefn.h for many Windows compilers
77 #if defined __MWERKS__ || defined __CYGWIN__
86 // TODO: Borland probably has _wgetcwd as well?
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
96 #define _MAXPATHLEN 1024
99 #ifndef INVALID_FILE_ATTRIBUTES
100 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 #if WXWIN_COMPATIBILITY_2_8
108 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
111 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
113 // VisualAge C++ V4.0 cannot have any external linkage const decs
114 // in headers included by more than one primary source
116 const int wxInvalidOffset
= -1;
119 // ============================================================================
121 // ============================================================================
123 // ----------------------------------------------------------------------------
124 // wrappers around standard POSIX functions
125 // ----------------------------------------------------------------------------
127 #if wxUSE_UNICODE && defined __BORLANDC__ \
128 && __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
130 // BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
131 // regardless of the mode parameter. This hack works around the problem by
132 // setting the mode with _wchmod.
134 int wxCRT_OpenW(const wchar_t *pathname
, int flags
, mode_t mode
)
138 // we only want to fix the mode when the file is actually created, so
139 // when creating first try doing it O_EXCL so we can tell if the file
140 // was already there.
141 if ((flags
& O_CREAT
) && !(flags
& O_EXCL
) && (mode
& wxS_IWUSR
) != 0)
144 int fd
= _wopen(pathname
, flags
| moreflags
, mode
);
146 // the file was actually created and needs fixing
147 if (fd
!= -1 && (flags
& O_CREAT
) != 0 && (mode
& wxS_IWUSR
) != 0)
150 _wchmod(pathname
, mode
);
151 fd
= _wopen(pathname
, flags
& ~(O_EXCL
| O_CREAT
));
153 // the open failed, but it may have been because the added O_EXCL stopped
154 // the opening of an existing file, so try again without.
155 else if (fd
== -1 && moreflags
!= 0)
157 fd
= _wopen(pathname
, flags
& ~O_CREAT
);
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 bool wxPathList::Add(const wxString
& path
)
171 // add a path separator to force wxFileName to interpret it always as a directory
172 // (i.e. if we are called with '/home/user' we want to consider it a folder and
173 // not, as wxFileName would consider, a filename).
174 wxFileName
fn(path
+ wxFileName::GetPathSeparator());
176 // add only normalized relative/absolute paths
177 // NB: we won't do wxPATH_NORM_DOTS in order to avoid problems when trying to
178 // normalize paths which starts with ".." (which can be normalized only if
179 // we use also wxPATH_NORM_ABSOLUTE - which we don't want to use).
180 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
183 wxString toadd
= fn
.GetPath();
184 if (Index(toadd
) == wxNOT_FOUND
)
185 wxArrayString::Add(toadd
); // do not add duplicates
190 void wxPathList::Add(const wxArrayString
&arr
)
192 for (size_t j
=0; j
< arr
.GetCount(); j
++)
196 // Add paths e.g. from the PATH environment variable
197 void wxPathList::AddEnvList (const wxString
& WXUNUSED_IN_WINCE(envVariable
))
199 // No environment variables on WinCE
202 // The space has been removed from the tokenizers, otherwise a
203 // path such as "C:\Program Files" would be split into 2 paths:
204 // "C:\Program" and "Files"; this is true for both Windows and Unix.
206 static const wxChar PATH_TOKS
[] =
207 #if defined(__WINDOWS__) || defined(__OS2__)
208 wxT(";"); // Don't separate with colon in DOS (used for drive)
214 if ( wxGetEnv(envVariable
, &val
) )
216 // split into an array of string the value of the env var
217 wxArrayString arr
= wxStringTokenize(val
, PATH_TOKS
);
218 WX_APPEND_ARRAY(*this, arr
);
220 #endif // !__WXWINCE__
223 // Given a full filename (with path), ensure that that file can
224 // be accessed again USING FILENAME ONLY by adding the path
225 // to the list if not already there.
226 bool wxPathList::EnsureFileAccessible (const wxString
& path
)
228 return Add(wxPathOnly(path
));
231 #if WXWIN_COMPATIBILITY_2_6
232 bool wxPathList::Member (const wxString
& path
) const
234 return Index(path
) != wxNOT_FOUND
;
238 wxString
wxPathList::FindValidPath (const wxString
& file
) const
240 // normalize the given string as it could be a path + a filename
241 // and not only a filename
245 // NB: normalize without making absolute otherwise calling this function with
246 // e.g. "b/c.txt" would result in removing the directory 'b' and the for loop
247 // below would only add to the paths of this list the 'c.txt' part when doing
248 // the existence checks...
249 // NB: we don't use wxPATH_NORM_DOTS here, too (see wxPathList::Add for more info)
250 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
251 return wxEmptyString
;
253 wxASSERT_MSG(!fn
.IsDir(), wxT("Cannot search for directories; only for files"));
255 strend
= fn
.GetFullName(); // search for the file name and ignore the path part
257 strend
= fn
.GetFullPath();
259 for (size_t i
=0; i
<GetCount(); i
++)
261 wxString strstart
= Item(i
);
262 if (!strstart
.IsEmpty() && strstart
.Last() != wxFileName::GetPathSeparator())
263 strstart
+= wxFileName::GetPathSeparator();
265 if (wxFileExists(strstart
+ strend
))
266 return strstart
+ strend
; // Found!
269 return wxEmptyString
; // Not found
272 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
) const
274 wxString f
= FindValidPath(file
);
275 if ( f
.empty() || wxIsAbsolutePath(f
) )
278 wxString buf
= ::wxGetCwd();
280 if ( !wxEndsWithPathSeparator(buf
) )
282 buf
+= wxFILE_SEP_PATH
;
289 // ----------------------------------------------------------------------------
290 // miscellaneous global functions
291 // ----------------------------------------------------------------------------
293 #if WXWIN_COMPATIBILITY_2_8
294 static inline wxChar
* MYcopystring(const wxString
& s
)
296 wxChar
* copy
= new wxChar
[s
.length() + 1];
297 return wxStrcpy(copy
, s
.c_str());
300 template<typename CharType
>
301 static inline CharType
* MYcopystring(const CharType
* s
)
303 CharType
* copy
= new CharType
[wxStrlen(s
) + 1];
304 return wxStrcpy(copy
, s
);
310 wxFileExists (const wxString
& filename
)
312 return wxFileName::FileExists(filename
);
316 wxIsAbsolutePath (const wxString
& filename
)
318 if (!filename
.empty())
320 // Unix like or Windows
321 if (filename
[0] == wxT('/'))
324 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
327 #if defined(__WINDOWS__) || defined(__OS2__)
329 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
336 #if WXWIN_COMPATIBILITY_2_8
338 * Strip off any extension (dot something) from end of file,
339 * IF one exists. Inserts zero into buffer.
344 static void wxDoStripExtension(T
*buffer
)
346 int len
= wxStrlen(buffer
);
350 if (buffer
[i
] == wxT('.'))
359 void wxStripExtension(char *buffer
) { wxDoStripExtension(buffer
); }
360 void wxStripExtension(wchar_t *buffer
) { wxDoStripExtension(buffer
); }
362 void wxStripExtension(wxString
& buffer
)
364 buffer
= wxFileName::StripExtension(buffer
);
367 // Destructive removal of /./ and /../ stuff
368 template<typename CharType
>
369 static CharType
*wxDoRealPath (CharType
*path
)
371 static const CharType SEP
= wxFILE_SEP_PATH
;
373 wxUnix2DosFilename(path
);
375 if (path
[0] && path
[1]) {
376 /* MATTHEW: special case "/./x" */
378 if (path
[2] == SEP
&& path
[1] == wxT('.'))
386 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
389 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--)
394 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
395 && (q
- 1 <= path
|| q
[-1] != SEP
))
398 if (path
[0] == wxT('\0'))
403 #if defined(__WXMSW__) || defined(__OS2__)
404 /* Check that path[2] is NULL! */
405 else if (path
[1] == wxT(':') && !path
[2])
414 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
422 char *wxRealPath(char *path
)
424 return wxDoRealPath(path
);
427 wchar_t *wxRealPath(wchar_t *path
)
429 return wxDoRealPath(path
);
432 wxString
wxRealPath(const wxString
& path
)
434 wxChar
*buf1
=MYcopystring(path
);
435 wxChar
*buf2
=wxRealPath(buf1
);
443 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
445 if (filename
.empty())
448 if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
)))
450 wxString buf
= ::wxGetCwd();
451 wxChar ch
= buf
.Last();
453 if (ch
!= wxT('\\') && ch
!= wxT('/'))
459 buf
<< wxFileFunctionsBuffer
;
460 buf
= wxRealPath( buf
);
461 return MYcopystring( buf
);
463 return MYcopystring( wxFileFunctionsBuffer
);
469 ~user/ => user's home dir
470 If the environment variable a = "foo" and b = "bar" then:
487 /* input name in name, pathname output to buf. */
489 template<typename CharType
>
490 static CharType
*wxDoExpandPath(CharType
*buf
, const wxString
& name
)
492 register CharType
*d
, *s
, *nm
;
493 CharType lnm
[_MAXPATHLEN
];
496 // Some compilers don't like this line.
497 // const CharType trimchars[] = wxT("\n \t");
499 CharType trimchars
[4];
500 trimchars
[0] = wxT('\n');
501 trimchars
[1] = wxT(' ');
502 trimchars
[2] = wxT('\t');
505 static const CharType SEP
= wxFILE_SEP_PATH
;
507 //wxUnix2DosFilename(path);
513 nm
= ::MYcopystring(static_cast<const CharType
*>(name
.c_str())); // Make a scratch copy
514 CharType
*nm_tmp
= nm
;
516 /* Skip leading whitespace and cr */
517 while (wxStrchr(trimchars
, *nm
) != NULL
)
519 /* And strip off trailing whitespace and cr */
520 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
521 while (q
-- && wxStrchr(trimchars
, *s
) != NULL
)
529 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
532 /* Expand inline environment variables */
550 while ((*d
++ = *s
) != 0) {
552 if (*s
== wxT('\\')) {
553 if ((*(d
- 1) = *++s
)!=0) {
561 // No env variables on WinCE
564 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
566 if (*s
++ == wxT('$'))
569 register CharType
*start
= d
;
570 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
571 register CharType
*value
;
572 while ((*d
++ = *s
) != 0)
573 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
578 value
= wxGetenv(braces
? start
+ 1 : start
);
580 for ((d
= start
- 1); (*d
++ = *value
++) != 0;)
594 /* Expand ~ and ~user */
597 if (nm
[0] == wxT('~') && !q
)
600 if (nm
[1] == SEP
|| nm
[1] == 0)
602 homepath
= wxGetUserHome(wxEmptyString
);
603 if (!homepath
.empty()) {
604 s
= (CharType
*)(const CharType
*)homepath
.c_str();
609 { /* ~user/filename */
610 register CharType
*nnm
;
611 for (s
= nm
; *s
&& *s
!= SEP
; s
++)
615 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
616 was_sep
= (*s
== SEP
);
617 nnm
= *s
? s
+ 1 : s
;
619 homepath
= wxGetUserHome(wxString(nm
+ 1));
620 if (homepath
.empty())
622 if (was_sep
) /* replace only if it was there: */
629 s
= (CharType
*)(const CharType
*)homepath
.c_str();
635 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
637 while (wxT('\0') != (*d
++ = *s
++))
640 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
644 while ((*d
++ = *s
++) != 0)
648 delete[] nm_tmp
; // clean up alloc
649 /* Now clean up the buffer */
650 return wxRealPath(buf
);
653 char *wxExpandPath(char *buf
, const wxString
& name
)
655 return wxDoExpandPath(buf
, name
);
658 wchar_t *wxExpandPath(wchar_t *buf
, const wxString
& name
)
660 return wxDoExpandPath(buf
, name
);
664 /* Contract Paths to be build upon an environment variable
667 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
669 The call wxExpandPath can convert these back!
672 wxContractPath (const wxString
& filename
,
673 const wxString
& WXUNUSED_IN_WINCE(envname
),
674 const wxString
& user
)
676 static wxChar dest
[_MAXPATHLEN
];
678 if (filename
.empty())
681 wxStrcpy (dest
, filename
);
683 wxUnix2DosFilename(dest
);
686 // Handle environment
690 if (!envname
.empty() && !(val
= wxGetenv (envname
)).empty() &&
691 (tcp
= wxStrstr (dest
, val
)) != NULL
)
693 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ val
.length());
696 wxStrcpy (tcp
, envname
);
697 wxStrcat (tcp
, wxT("}"));
698 wxStrcat (tcp
, wxFileFunctionsBuffer
);
702 // Handle User's home (ignore root homes!)
703 val
= wxGetUserHome (user
);
707 const size_t len
= val
.length();
711 if (wxStrncmp(dest
, val
, len
) == 0)
713 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
715 wxStrcat(wxFileFunctionsBuffer
, user
);
716 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
717 wxStrcpy (dest
, wxFileFunctionsBuffer
);
723 #endif // #if WXWIN_COMPATIBILITY_2_8
725 // Return just the filename, not the path (basename)
726 wxChar
*wxFileNameFromPath (wxChar
*path
)
729 wxString n
= wxFileNameFromPath(p
);
731 return path
+ p
.length() - n
.length();
734 wxString
wxFileNameFromPath (const wxString
& path
)
737 wxFileName::SplitPath(path
, NULL
, &name
, &ext
);
739 wxString fullname
= name
;
742 fullname
<< wxFILE_SEP_EXT
<< ext
;
748 // Return just the directory, or NULL if no directory
750 wxPathOnly (wxChar
*path
)
754 static wxChar buf
[_MAXPATHLEN
];
757 wxStrcpy (buf
, path
);
759 int l
= wxStrlen(path
);
762 // Search backward for a backward or forward slash
765 // Unix like or Windows
766 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
772 if (path
[i
] == wxT(']'))
781 #if defined(__WXMSW__) || defined(__OS2__)
782 // Try Drive specifier
783 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
785 // A:junk --> A:. (since A:.\junk Not A:\junk)
795 // Return just the directory, or NULL if no directory
796 wxString
wxPathOnly (const wxString
& path
)
800 wxChar buf
[_MAXPATHLEN
];
805 int l
= path
.length();
808 // Search backward for a backward or forward slash
811 // Unix like or Windows
812 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
814 // Don't return an empty string
818 return wxString(buf
);
821 if (path
[i
] == wxT(']'))
824 return wxString(buf
);
830 #if defined(__WXMSW__) || defined(__OS2__)
831 // Try Drive specifier
832 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
834 // A:junk --> A:. (since A:.\junk Not A:\junk)
837 return wxString(buf
);
841 return wxEmptyString
;
844 // Utility for converting delimiters in DOS filenames to UNIX style
845 // and back again - or we get nasty problems with delimiters.
846 // Also, convert to lower case, since case is significant in UNIX.
848 #if defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)
850 #define kDefaultPathStyle kCFURLPOSIXPathStyle
852 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
855 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
856 if ( additionalPathComponent
)
858 CFURLRef parentURLRef
= fullURLRef
;
859 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
860 additionalPathComponent
,false);
861 CFRelease( parentURLRef
) ;
863 CFStringRef cfString
= CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
);
864 CFRelease( fullURLRef
) ;
865 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfString
);
866 CFRelease( cfString
);
867 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
868 return wxCFStringRef(cfMutableString
).AsString();
871 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
873 OSStatus err
= noErr
;
874 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(path
));
875 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
876 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
877 CFRelease( cfMutableString
);
880 if ( CFURLGetFSRef(url
, fsRef
) == false )
891 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
893 CFStringRef cfname
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
896 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfname
);
898 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
899 return wxCFStringRef(cfMutableString
).AsString() ;
904 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
907 if ( FSpMakeFSRef( spec
, &fsRef
) == noErr
)
909 return wxMacFSRefToPath( &fsRef
) ;
911 return wxEmptyString
;
914 void wxMacFilename2FSSpec( const wxString
& path
, FSSpec
*spec
)
916 OSStatus err
= noErr
;
918 wxMacPathToFSRef( path
, &fsRef
);
919 err
= FSGetCatalogInfo(&fsRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
927 #if WXWIN_COMPATIBILITY_2_8
930 static void wxDoDos2UnixFilename(T
*s
)
939 *s
= wxTolower(*s
); // Case INDEPENDENT
945 void wxDos2UnixFilename(char *s
) { wxDoDos2UnixFilename(s
); }
946 void wxDos2UnixFilename(wchar_t *s
) { wxDoDos2UnixFilename(s
); }
950 #if defined(__WXMSW__) || defined(__OS2__)
951 wxDoUnix2DosFilename(T
*s
)
953 wxDoUnix2DosFilename(T
*WXUNUSED(s
) )
956 // Yes, I really mean this to happen under DOS only! JACS
957 #if defined(__WXMSW__) || defined(__OS2__)
968 void wxUnix2DosFilename(char *s
) { wxDoUnix2DosFilename(s
); }
969 void wxUnix2DosFilename(wchar_t *s
) { wxDoUnix2DosFilename(s
); }
971 #endif // #if WXWIN_COMPATIBILITY_2_8
973 // Concatenate two files to form third
975 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
979 wxFile
in1(file1
), in2(file2
);
980 wxTempFile
out(file3
);
982 if ( !in1
.IsOpened() || !in2
.IsOpened() || !out
.IsOpened() )
986 unsigned char buf
[1024];
988 for( int i
=0; i
<2; i
++)
990 wxFile
*in
= i
==0 ? &in1
: &in2
;
992 if ( (ofs
= in
->Read(buf
,WXSIZEOF(buf
))) == wxInvalidOffset
) return false;
994 if ( !out
.Write(buf
,ofs
) )
996 } while ( ofs
== (ssize_t
)WXSIZEOF(buf
) );
1011 // helper of generic implementation of wxCopyFile()
1012 #if !(defined(__WIN32__) || defined(__OS2__) || defined(__PALMOS__)) && \
1016 wxDoCopyFile(wxFile
& fileIn
,
1017 const wxStructStat
& fbuf
,
1018 const wxString
& filenameDst
,
1021 // reset the umask as we want to create the file with exactly the same
1022 // permissions as the original one
1025 // create file2 with the same permissions than file1 and open it for
1029 if ( !fileOut
.Create(filenameDst
, overwrite
, fbuf
.st_mode
& 0777) )
1032 // copy contents of file1 to file2
1036 ssize_t count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1037 if ( count
== wxInvalidOffset
)
1044 if ( fileOut
.Write(buf
, count
) < (size_t)count
)
1048 // we can expect fileIn to be closed successfully, but we should ensure
1049 // that fileOut was closed as some write errors (disk full) might not be
1050 // detected before doing this
1051 return fileIn
.Close() && fileOut
.Close();
1054 #endif // generic implementation of wxCopyFile
1058 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1060 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1061 // CopyFile() copies file attributes and modification time too, so use it
1062 // instead of our code if available
1064 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1065 if ( !::CopyFile(file1
.fn_str(), file2
.fn_str(), !overwrite
) )
1067 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1068 file1
.c_str(), file2
.c_str());
1072 #elif defined(__OS2__)
1073 if ( ::DosCopy(file1
.c_str(), file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1075 #elif defined(__PALMOS__)
1076 // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
1078 #elif wxUSE_FILE // !Win32
1081 // get permissions of file1
1082 if ( wxStat( file1
, &fbuf
) != 0 )
1084 // the file probably doesn't exist or we haven't the rights to read
1086 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1091 // open file1 for reading
1092 wxFile
fileIn(file1
, wxFile::read
);
1093 if ( !fileIn
.IsOpened() )
1096 // remove file2, if it exists. This is needed for creating
1097 // file2 with the correct permissions in the next step
1098 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1100 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1105 wxDoCopyFile(fileIn
, fbuf
, file2
, overwrite
);
1107 #if defined(__WXMAC__) || defined(__WXCOCOA__)
1108 // copy the resource fork of the file too if it's present
1109 wxString pathRsrcOut
;
1113 // suppress error messages from this block as resource forks don't have
1117 // it's not enough to check for file existence: it always does on HFS
1118 // but is empty for files without resources
1119 if ( fileRsrcIn
.Open(file1
+ wxT("/..namedfork/rsrc")) &&
1120 fileRsrcIn
.Length() > 0 )
1122 // we must be using HFS or another filesystem with resource fork
1123 // support, suppose that destination file system also is HFS[-like]
1124 pathRsrcOut
= file2
+ wxT("/..namedfork/rsrc");
1126 else // check if we have resource fork in separate file (non-HFS case)
1128 wxFileName
fnRsrc(file1
);
1129 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1132 if ( fileRsrcIn
.Open( fnRsrc
.GetFullPath() ) )
1135 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1137 pathRsrcOut
= fnRsrc
.GetFullPath();
1142 if ( !pathRsrcOut
.empty() )
1144 if ( !wxDoCopyFile(fileRsrcIn
, fbuf
, pathRsrcOut
, overwrite
) )
1147 #endif // wxMac || wxCocoa
1149 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1150 // no chmod in VA. Should be some permission API for HPFS386 partitions
1152 if ( chmod(file2
.fn_str(), fbuf
.st_mode
) != 0 )
1154 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1158 #endif // OS/2 || Mac
1160 #else // !Win32 && ! wxUSE_FILE
1162 // impossible to simulate with wxWidgets API
1165 wxUnusedVar(overwrite
);
1168 #endif // __WXMSW__ && __WIN32__
1174 wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1176 if ( !overwrite
&& wxFileExists(file2
) )
1180 _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
1181 file1
.c_str(), file2
.c_str()
1187 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
1188 // Normal system call
1189 if ( wxRename (file1
, file2
) == 0 )
1194 if (wxCopyFile(file1
, file2
, overwrite
)) {
1195 wxRemoveFile(file1
);
1202 bool wxRemoveFile(const wxString
& file
)
1204 #if defined(__VISUALC__) \
1205 || defined(__BORLANDC__) \
1206 || defined(__WATCOMC__) \
1207 || defined(__DMC__) \
1208 || defined(__GNUWIN32__) \
1209 || (defined(__MWERKS__) && defined(__MSL__))
1210 int res
= wxRemove(file
);
1211 #elif defined(__WXMAC__)
1212 int res
= unlink(file
.fn_str());
1213 #elif defined(__WXPALMOS__)
1215 // TODO with VFSFileDelete()
1217 int res
= unlink(file
.fn_str());
1223 bool wxMkdir(const wxString
& dir
, int perm
)
1225 #if defined(__WXPALMOS__)
1228 #if defined(__WXMAC__) && !defined(__UNIX__)
1229 if ( mkdir(dir
.fn_str(), 0) != 0 )
1231 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1232 // for the GNU compiler
1233 #elif (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || \
1234 (defined(__GNUWIN32__) && !defined(__MINGW32__)) || \
1235 defined(__WINE__) || defined(__WXMICROWIN__)
1236 const wxChar
*dirname
= dir
.c_str();
1239 if ( mkdir(wxFNCONV(dirname
)) != 0 )
1241 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1243 #elif defined(__OS2__)
1245 if (::DosCreateDir(dir
.c_str(), NULL
) != 0) // enhance for EAB's??
1246 #elif defined(__DOS__)
1247 const wxChar
*dirname
= dir
.c_str();
1248 #if defined(__WATCOMC__)
1250 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1251 #elif defined(__DJGPP__)
1252 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1254 #error "Unsupported DOS compiler!"
1256 #else // !MSW, !DOS and !OS/2 VAC++
1259 if ( CreateDirectory(dir
.fn_str(), NULL
) == 0 )
1261 if ( wxMkDir(dir
.fn_str()) != 0 )
1265 wxLogSysError(_("Directory '%s' couldn't be created"), dir
);
1270 #endif // PALMOS/!PALMOS
1273 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1275 #if defined(__VMS__)
1276 return false; //to be changed since rmdir exists in VMS7.x
1277 #elif defined(__WXPALMOS__)
1278 // TODO with VFSFileRename()
1281 #if defined(__OS2__)
1282 if ( ::DosDeleteDir(dir
.c_str()) != 0 )
1283 #elif defined(__WXWINCE__)
1284 if ( RemoveDirectory(dir
.fn_str()) == 0 )
1286 if ( wxRmDir(dir
.fn_str()) != 0 )
1289 wxLogSysError(_("Directory '%s' couldn't be deleted"), dir
);
1294 #endif // PALMOS/!PALMOS
1297 // does the path exists? (may have or not '/' or '\\' at the end)
1298 bool wxDirExists(const wxString
& pathName
)
1300 return wxFileName::DirExists(pathName
);
1303 #if WXWIN_COMPATIBILITY_2_8
1305 // Get a temporary filename, opening and closing the file.
1306 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1309 if ( !wxGetTempFileName(prefix
, filename
) )
1314 // work around the PalmOS pacc compiler bug
1315 wxStrcpy(buf
, filename
.data());
1317 wxStrcpy(buf
, filename
);
1320 buf
= MYcopystring(filename
);
1325 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1328 buf
= wxFileName::CreateTempFileName(prefix
);
1330 return !buf
.empty();
1331 #else // !wxUSE_FILE
1332 wxUnusedVar(prefix
);
1336 #endif // wxUSE_FILE/!wxUSE_FILE
1339 #endif // #if WXWIN_COMPATIBILITY_2_8
1341 // Get first file name matching given wild card.
1343 static wxDir
*gs_dir
= NULL
;
1344 static wxString gs_dirPath
;
1346 wxString
wxFindFirstFile(const wxString
& spec
, int flags
)
1348 wxFileName::SplitPath(spec
, &gs_dirPath
, NULL
, NULL
);
1349 if ( gs_dirPath
.empty() )
1350 gs_dirPath
= wxT(".");
1351 if ( !wxEndsWithPathSeparator(gs_dirPath
) )
1352 gs_dirPath
<< wxFILE_SEP_PATH
;
1354 delete gs_dir
; // can be NULL, this is ok
1355 gs_dir
= new wxDir(gs_dirPath
);
1357 if ( !gs_dir
->IsOpened() )
1359 wxLogSysError(_("Can not enumerate files '%s'"), spec
);
1360 return wxEmptyString
;
1366 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1367 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1368 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1372 gs_dir
->GetFirst(&result
, wxFileNameFromPath(spec
), dirFlags
);
1373 if ( result
.empty() )
1379 return gs_dirPath
+ result
;
1382 wxString
wxFindNextFile()
1384 wxCHECK_MSG( gs_dir
, "", "You must call wxFindFirstFile before!" );
1387 gs_dir
->GetNext(&result
);
1389 if ( result
.empty() )
1395 return gs_dirPath
+ result
;
1399 // Get current working directory.
1400 // If buf is NULL, allocates space using new, else copies into buf.
1401 // wxGetWorkingDirectory() is obsolete, use wxGetCwd()
1402 // wxDoGetCwd() is their common core to be moved
1403 // to wxGetCwd() once wxGetWorkingDirectory() will be removed.
1404 // Do not expose wxDoGetCwd in headers!
1406 wxChar
*wxDoGetCwd(wxChar
*buf
, int sz
)
1408 #if defined(__WXPALMOS__)
1410 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1412 #elif defined(__WXWINCE__)
1414 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1419 buf
= new wxChar
[sz
+ 1];
1422 bool ok
wxDUMMY_INITIALIZE(false);
1424 // for the compilers which have Unicode version of _getcwd(), call it
1425 // directly, for the others call the ANSI version and do the translation
1428 #else // wxUSE_UNICODE
1429 bool needsANSI
= true;
1431 #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
1432 char cbuf
[_MAXPATHLEN
];
1436 #if wxUSE_UNICODE_MSLU
1437 if ( wxGetOsVersion() != wxOS_WINDOWS_9X
)
1439 char *cbuf
= NULL
; // never really used because needsANSI will always be false
1442 ok
= _wgetcwd(buf
, sz
) != NULL
;
1448 #endif // wxUSE_UNICODE
1450 #if defined(_MSC_VER) || defined(__MINGW32__)
1451 ok
= _getcwd(cbuf
, sz
) != NULL
;
1452 #elif defined(__OS2__)
1454 ULONG ulDriveNum
= 0;
1455 ULONG ulDriveMap
= 0;
1456 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
1461 rc
= ::DosQueryCurrentDir( 0 // current drive
1465 cbuf
[0] = char('A' + (ulDriveNum
- 1));
1470 #else // !Win32/VC++ !Mac !OS2
1471 ok
= getcwd(cbuf
, sz
) != NULL
;
1475 // finally convert the result to Unicode if needed
1476 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1477 #endif // wxUSE_UNICODE
1482 wxLogSysError(_("Failed to get the working directory"));
1484 // VZ: the old code used to return "." on error which didn't make any
1485 // sense at all to me - empty string is a better error indicator
1486 // (NULL might be even better but I'm afraid this could lead to
1487 // problems with the old code assuming the return is never NULL)
1490 else // ok, but we might need to massage the path into the right format
1493 // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
1494 // with / deliminers. We don't like that.
1495 for (wxChar
*ch
= buf
; *ch
; ch
++)
1497 if (*ch
== wxT('/'))
1502 // MBN: we hope that in the case the user is compiling a GTK+/Motif app,
1503 // he needs Unix as opposed to Win32 pathnames
1504 #if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
1505 // another example of DOS/Unix mix (Cygwin)
1506 wxString pathUnix
= buf
;
1508 char bufA
[_MAXPATHLEN
];
1509 cygwin_conv_to_full_win32_path(pathUnix
.mb_str(wxConvFile
), bufA
);
1510 wxConvFile
.MB2WC(buf
, bufA
, sz
);
1512 cygwin_conv_to_full_win32_path(pathUnix
, buf
);
1513 #endif // wxUSE_UNICODE
1514 #endif // __CYGWIN__
1527 #if WXWIN_COMPATIBILITY_2_6
1528 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1530 return wxDoGetCwd(buf
,sz
);
1532 #endif // WXWIN_COMPATIBILITY_2_6
1537 wxDoGetCwd(wxStringBuffer(str
, _MAXPATHLEN
), _MAXPATHLEN
);
1541 bool wxSetWorkingDirectory(const wxString
& d
)
1543 #if defined(__OS2__)
1546 ::DosSetDefaultDisk(wxToupper(d
[0]) - wxT('A') + 1);
1547 // do not call DosSetCurrentDir when just changing drive,
1548 // since it requires e.g. "d:." instead of "d:"!
1549 if (d
.length() == 2)
1552 return (::DosSetCurrentDir(d
.c_str()) == 0);
1553 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1554 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1555 #elif defined(__WINDOWS__)
1559 // No equivalent in WinCE
1563 return (bool)(SetCurrentDirectory(d
.fn_str()) != 0);
1566 // Must change drive, too.
1567 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1570 wxChar firstChar
= d
[0];
1574 firstChar
= firstChar
- 32;
1576 // To a drive number
1577 unsigned int driveNo
= firstChar
- 64;
1580 unsigned int noDrives
;
1581 _dos_setdrive(driveNo
, &noDrives
);
1584 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1592 // Get the OS directory if appropriate (such as the Windows directory).
1593 // On non-Windows platform, probably just return the empty string.
1594 wxString
wxGetOSDirectory()
1597 return wxString(wxT("\\Windows"));
1598 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1600 GetWindowsDirectory(buf
, 256);
1601 return wxString(buf
);
1602 #elif defined(__WXMAC__) && wxOSX_USE_CARBON
1603 return wxMacFindFolder(kOnSystemDisk
, 'macs', false);
1605 return wxEmptyString
;
1609 bool wxEndsWithPathSeparator(const wxString
& filename
)
1611 return !filename
.empty() && wxIsPathSeparator(filename
.Last());
1614 // find a file in a list of directories, returns false if not found
1615 bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
)
1617 // we assume that it's not empty
1618 wxCHECK_MSG( !szFile
.empty(), false,
1619 wxT("empty file name in wxFindFileInPath"));
1621 // skip path separator in the beginning of the file name if present
1623 if ( wxIsPathSeparator(szFile
[0u]) )
1624 szFile2
= szFile
.Mid(1);
1628 wxStringTokenizer
tkn(szPath
, wxPATH_SEP
);
1630 while ( tkn
.HasMoreTokens() )
1632 wxString strFile
= tkn
.GetNextToken();
1633 if ( !wxEndsWithPathSeparator(strFile
) )
1634 strFile
+= wxFILE_SEP_PATH
;
1637 if ( wxFileExists(strFile
) )
1647 #if WXWIN_COMPATIBILITY_2_8
1648 void WXDLLIMPEXP_BASE
wxSplitPath(const wxString
& fileName
,
1653 wxFileName::SplitPath(fileName
, pstrPath
, pstrName
, pstrExt
);
1655 #endif // #if WXWIN_COMPATIBILITY_2_8
1659 time_t WXDLLIMPEXP_BASE
wxFileModificationTime(const wxString
& filename
)
1662 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1665 return mtime
.GetTicks();
1668 #endif // wxUSE_DATETIME
1671 // Parses the filterStr, returning the number of filters.
1672 // Returns 0 if none or if there's a problem.
1673 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1675 int WXDLLIMPEXP_BASE
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1676 wxArrayString
& descriptions
,
1677 wxArrayString
& filters
)
1679 descriptions
.Clear();
1682 wxString
str(filterStr
);
1684 wxString description
, filter
;
1686 while( pos
!= wxNOT_FOUND
)
1688 pos
= str
.Find(wxT('|'));
1689 if ( pos
== wxNOT_FOUND
)
1691 // if there are no '|'s at all in the string just take the entire
1692 // string as filter and make description empty for later autocompletion
1693 if ( filters
.IsEmpty() )
1695 descriptions
.Add(wxEmptyString
);
1696 filters
.Add(filterStr
);
1700 wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
1706 description
= str
.Left(pos
);
1707 str
= str
.Mid(pos
+ 1);
1708 pos
= str
.Find(wxT('|'));
1709 if ( pos
== wxNOT_FOUND
)
1715 filter
= str
.Left(pos
);
1716 str
= str
.Mid(pos
+ 1);
1719 descriptions
.Add(description
);
1720 filters
.Add(filter
);
1723 #if defined(__WXMOTIF__)
1724 // split it so there is one wildcard per entry
1725 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1727 pos
= filters
[i
].Find(wxT(';'));
1728 if (pos
!= wxNOT_FOUND
)
1730 // first split only filters
1731 descriptions
.Insert(descriptions
[i
],i
+1);
1732 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1733 filters
[i
]=filters
[i
].Left(pos
);
1735 // autoreplace new filter in description with pattern:
1736 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1737 // cause split into:
1738 // C/C++ Files(*.cpp)|*.cpp
1739 // C/C++ Files(*.c;*.h)|*.c;*.h
1740 // and next iteration cause another split into:
1741 // C/C++ Files(*.cpp)|*.cpp
1742 // C/C++ Files(*.c)|*.c
1743 // C/C++ Files(*.h)|*.h
1744 for ( size_t k
=i
;k
<i
+2;k
++ )
1746 pos
= descriptions
[k
].Find(filters
[k
]);
1747 if (pos
!= wxNOT_FOUND
)
1749 wxString before
= descriptions
[k
].Left(pos
);
1750 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1751 pos
= before
.Find(wxT('('),true);
1752 if (pos
>before
.Find(wxT(')'),true))
1754 before
= before
.Left(pos
+1);
1755 before
<< filters
[k
];
1756 pos
= after
.Find(wxT(')'));
1757 int pos1
= after
.Find(wxT('('));
1758 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1760 before
<< after
.Mid(pos
);
1761 descriptions
[k
] = before
;
1771 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1773 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1775 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1779 return filters
.GetCount();
1782 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1783 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1785 // quoting the MSDN: "To obtain a handle to a directory, call the
1786 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1787 // doesn't work under Win9x/ME but then it's not needed there anyhow
1788 const DWORD dwAttr
= ::GetFileAttributes(path
.fn_str());
1789 if ( dwAttr
== INVALID_FILE_ATTRIBUTES
)
1791 // file probably doesn't exist at all
1795 if ( wxGetOsVersion() == wxOS_WINDOWS_9X
)
1797 // FAT directories always allow all access, even if they have the
1798 // readonly flag set, and FAT files can only be read-only
1799 return (dwAttr
& FILE_ATTRIBUTE_DIRECTORY
) ||
1800 (access
!= GENERIC_WRITE
||
1801 !(dwAttr
& FILE_ATTRIBUTE_READONLY
));
1804 HANDLE h
= ::CreateFile
1808 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1811 dwAttr
& FILE_ATTRIBUTE_DIRECTORY
1812 ? FILE_FLAG_BACKUP_SEMANTICS
1816 if ( h
!= INVALID_HANDLE_VALUE
)
1819 return h
!= INVALID_HANDLE_VALUE
;
1821 #endif // __WINDOWS__
1823 bool wxIsWritable(const wxString
&path
)
1825 #if defined( __UNIX__ ) || defined(__OS2__)
1826 // access() will take in count also symbolic links
1827 return wxAccess(path
.c_str(), W_OK
) == 0;
1828 #elif defined( __WINDOWS__ )
1829 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1837 bool wxIsReadable(const wxString
&path
)
1839 #if defined( __UNIX__ ) || defined(__OS2__)
1840 // access() will take in count also symbolic links
1841 return wxAccess(path
.c_str(), R_OK
) == 0;
1842 #elif defined( __WINDOWS__ )
1843 return wxCheckWin32Permission(path
, GENERIC_READ
);
1851 bool wxIsExecutable(const wxString
&path
)
1853 #if defined( __UNIX__ ) || defined(__OS2__)
1854 // access() will take in count also symbolic links
1855 return wxAccess(path
.c_str(), X_OK
) == 0;
1856 #elif defined( __WINDOWS__ )
1857 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1865 // Return the type of an open file
1867 // Some file types on some platforms seem seekable but in fact are not.
1868 // The main use of this function is to allow such cases to be detected
1869 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1871 // This is important for the archive streams, which benefit greatly from
1872 // being able to seek on a stream, but which will produce corrupt archives
1873 // if they unknowingly seek on a non-seekable stream.
1875 // wxFILE_KIND_DISK is a good catch all return value, since other values
1876 // disable features of the archive streams. Some other value must be returned
1877 // for a file type that appears seekable but isn't.
1880 // * Pipes on Windows
1881 // * Files on VMS with a record format other than StreamLF
1883 wxFileKind
wxGetFileKind(int fd
)
1885 #if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1886 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1888 case FILE_TYPE_CHAR
:
1889 return wxFILE_KIND_TERMINAL
;
1890 case FILE_TYPE_DISK
:
1891 return wxFILE_KIND_DISK
;
1892 case FILE_TYPE_PIPE
:
1893 return wxFILE_KIND_PIPE
;
1896 return wxFILE_KIND_UNKNOWN
;
1898 #elif defined(__UNIX__)
1900 return wxFILE_KIND_TERMINAL
;
1905 if (S_ISFIFO(st
.st_mode
))
1906 return wxFILE_KIND_PIPE
;
1907 if (!S_ISREG(st
.st_mode
))
1908 return wxFILE_KIND_UNKNOWN
;
1910 #if defined(__VMS__)
1911 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1912 return wxFILE_KIND_UNKNOWN
;
1915 return wxFILE_KIND_DISK
;
1918 #define wxFILEKIND_STUB
1920 return wxFILE_KIND_DISK
;
1924 wxFileKind
wxGetFileKind(FILE *fp
)
1926 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1927 // Should be fixed in version 1.4.
1928 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1930 return wxFILE_KIND_DISK
;
1931 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WINE__)
1932 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1934 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1939 //------------------------------------------------------------------------
1940 // wild character routines
1941 //------------------------------------------------------------------------
1943 bool wxIsWild( const wxString
& pattern
)
1945 for ( wxString::const_iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
)
1947 switch ( (*p
).GetValue() )
1956 if ( ++p
== pattern
.end() )
1964 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1966 * The match procedure is public domain code (from ircII's reg.c)
1967 * but modified to suit our tastes (RN: No "%" syntax I guess)
1970 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1974 /* Match if both are empty. */
1978 const wxChar
*m
= pat
.c_str(),
1986 if (dot_special
&& (*n
== wxT('.')))
1988 /* Never match so that hidden Unix files
1989 * are never found. */
2002 else if (*m
== wxT('?'))
2010 if (*m
== wxT('\\'))
2013 /* Quoting "nothing" is a bad thing */
2020 * If we are out of both strings or we just
2021 * saw a wildcard, then we can say we have a
2032 * We could check for *n == NULL at this point, but
2033 * since it's more common to have a character there,
2034 * check to see if they match first (m and n) and
2035 * then if they don't match, THEN we can check for
2051 * If there are no more characters in the
2052 * string, but we still need to find another
2053 * character (*m != NULL), then it will be
2054 * impossible to match it
2073 #pragma warning(default:4706) // assignment within conditional expression