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/missing.h"
65 #include "wx/msw/mslu.h"
67 // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
68 // and for cygwin_conv_path()
70 // note that it must be included after <windows.h>
73 #include <sys/cygwin.h>
74 #include <cygwin/version.h>
76 #endif // __GNUWIN32__
78 // io.h is needed for _get_osfhandle()
79 // Already included by filefn.h for many Windows compilers
80 #if defined __CYGWIN__
89 // TODO: Borland probably has _wgetcwd as well?
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
99 #define _MAXPATHLEN 1024
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 #if WXWIN_COMPATIBILITY_2_8
107 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
110 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
112 // VisualAge C++ V4.0 cannot have any external linkage const decs
113 // in headers included by more than one primary source
115 const int wxInvalidOffset
= -1;
118 // ============================================================================
120 // ============================================================================
122 // ----------------------------------------------------------------------------
123 // wrappers around standard POSIX functions
124 // ----------------------------------------------------------------------------
126 #if wxUSE_UNICODE && defined __BORLANDC__ \
127 && __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
129 // BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
130 // regardless of the mode parameter. This hack works around the problem by
131 // setting the mode with _wchmod.
133 int wxCRT_OpenW(const wchar_t *pathname
, int flags
, mode_t mode
)
137 // we only want to fix the mode when the file is actually created, so
138 // when creating first try doing it O_EXCL so we can tell if the file
139 // was already there.
140 if ((flags
& O_CREAT
) && !(flags
& O_EXCL
) && (mode
& wxS_IWUSR
) != 0)
143 int fd
= _wopen(pathname
, flags
| moreflags
, mode
);
145 // the file was actually created and needs fixing
146 if (fd
!= -1 && (flags
& O_CREAT
) != 0 && (mode
& wxS_IWUSR
) != 0)
149 _wchmod(pathname
, mode
);
150 fd
= _wopen(pathname
, flags
& ~(O_EXCL
| O_CREAT
));
152 // the open failed, but it may have been because the added O_EXCL stopped
153 // the opening of an existing file, so try again without.
154 else if (fd
== -1 && moreflags
!= 0)
156 fd
= _wopen(pathname
, flags
& ~O_CREAT
);
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 bool wxPathList::Add(const wxString
& path
)
170 // add a path separator to force wxFileName to interpret it always as a directory
171 // (i.e. if we are called with '/home/user' we want to consider it a folder and
172 // not, as wxFileName would consider, a filename).
173 wxFileName
fn(path
+ wxFileName::GetPathSeparator());
175 // add only normalized relative/absolute paths
176 // NB: we won't do wxPATH_NORM_DOTS in order to avoid problems when trying to
177 // normalize paths which starts with ".." (which can be normalized only if
178 // we use also wxPATH_NORM_ABSOLUTE - which we don't want to use).
179 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
182 wxString toadd
= fn
.GetPath();
183 if (Index(toadd
) == wxNOT_FOUND
)
184 wxArrayString::Add(toadd
); // do not add duplicates
189 void wxPathList::Add(const wxArrayString
&arr
)
191 for (size_t j
=0; j
< arr
.GetCount(); j
++)
195 // Add paths e.g. from the PATH environment variable
196 void wxPathList::AddEnvList (const wxString
& WXUNUSED_IN_WINCE(envVariable
))
198 // No environment variables on WinCE
201 // The space has been removed from the tokenizers, otherwise a
202 // path such as "C:\Program Files" would be split into 2 paths:
203 // "C:\Program" and "Files"; this is true for both Windows and Unix.
205 static const wxChar PATH_TOKS
[] =
206 #if defined(__WINDOWS__) || defined(__OS2__)
207 wxT(";"); // Don't separate with colon in DOS (used for drive)
213 if ( wxGetEnv(envVariable
, &val
) )
215 // split into an array of string the value of the env var
216 wxArrayString arr
= wxStringTokenize(val
, PATH_TOKS
);
217 WX_APPEND_ARRAY(*this, arr
);
219 #endif // !__WXWINCE__
222 // Given a full filename (with path), ensure that that file can
223 // be accessed again USING FILENAME ONLY by adding the path
224 // to the list if not already there.
225 bool wxPathList::EnsureFileAccessible (const wxString
& path
)
227 return Add(wxPathOnly(path
));
230 #if WXWIN_COMPATIBILITY_2_6
231 bool wxPathList::Member (const wxString
& path
) const
233 return Index(path
) != wxNOT_FOUND
;
237 wxString
wxPathList::FindValidPath (const wxString
& file
) const
239 // normalize the given string as it could be a path + a filename
240 // and not only a filename
244 // NB: normalize without making absolute otherwise calling this function with
245 // e.g. "b/c.txt" would result in removing the directory 'b' and the for loop
246 // below would only add to the paths of this list the 'c.txt' part when doing
247 // the existence checks...
248 // NB: we don't use wxPATH_NORM_DOTS here, too (see wxPathList::Add for more info)
249 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
250 return wxEmptyString
;
252 wxASSERT_MSG(!fn
.IsDir(), wxT("Cannot search for directories; only for files"));
254 strend
= fn
.GetFullName(); // search for the file name and ignore the path part
256 strend
= fn
.GetFullPath();
258 for (size_t i
=0; i
<GetCount(); i
++)
260 wxString strstart
= Item(i
);
261 if (!strstart
.IsEmpty() && strstart
.Last() != wxFileName::GetPathSeparator())
262 strstart
+= wxFileName::GetPathSeparator();
264 if (wxFileExists(strstart
+ strend
))
265 return strstart
+ strend
; // Found!
268 return wxEmptyString
; // Not found
271 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
) const
273 wxString f
= FindValidPath(file
);
274 if ( f
.empty() || wxIsAbsolutePath(f
) )
277 wxString buf
= ::wxGetCwd();
279 if ( !wxEndsWithPathSeparator(buf
) )
281 buf
+= wxFILE_SEP_PATH
;
288 // ----------------------------------------------------------------------------
289 // miscellaneous global functions
290 // ----------------------------------------------------------------------------
292 #if WXWIN_COMPATIBILITY_2_8
293 static inline wxChar
* MYcopystring(const wxString
& s
)
295 wxChar
* copy
= new wxChar
[s
.length() + 1];
296 return wxStrcpy(copy
, s
.c_str());
299 template<typename CharType
>
300 static inline CharType
* MYcopystring(const CharType
* s
)
302 CharType
* copy
= new CharType
[wxStrlen(s
) + 1];
303 return wxStrcpy(copy
, s
);
309 wxFileExists (const wxString
& filename
)
311 return wxFileName::FileExists(filename
);
315 wxIsAbsolutePath (const wxString
& filename
)
317 if (!filename
.empty())
319 // Unix like or Windows
320 if (filename
[0] == wxT('/'))
323 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
326 #if defined(__WINDOWS__) || defined(__OS2__)
328 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
335 #if WXWIN_COMPATIBILITY_2_8
337 * Strip off any extension (dot something) from end of file,
338 * IF one exists. Inserts zero into buffer.
343 static void wxDoStripExtension(T
*buffer
)
345 int len
= wxStrlen(buffer
);
349 if (buffer
[i
] == wxT('.'))
358 void wxStripExtension(char *buffer
) { wxDoStripExtension(buffer
); }
359 void wxStripExtension(wchar_t *buffer
) { wxDoStripExtension(buffer
); }
361 void wxStripExtension(wxString
& buffer
)
363 buffer
= wxFileName::StripExtension(buffer
);
366 // Destructive removal of /./ and /../ stuff
367 template<typename CharType
>
368 static CharType
*wxDoRealPath (CharType
*path
)
370 static const CharType SEP
= wxFILE_SEP_PATH
;
372 wxUnix2DosFilename(path
);
374 if (path
[0] && path
[1]) {
375 /* MATTHEW: special case "/./x" */
377 if (path
[2] == SEP
&& path
[1] == wxT('.'))
385 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
388 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--)
393 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
394 && (q
- 1 <= path
|| q
[-1] != SEP
))
397 if (path
[0] == wxT('\0'))
402 #if defined(__WINDOWS__) || defined(__OS2__)
403 /* Check that path[2] is NULL! */
404 else if (path
[1] == wxT(':') && !path
[2])
413 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
421 char *wxRealPath(char *path
)
423 return wxDoRealPath(path
);
426 wchar_t *wxRealPath(wchar_t *path
)
428 return wxDoRealPath(path
);
431 wxString
wxRealPath(const wxString
& path
)
433 wxChar
*buf1
=MYcopystring(path
);
434 wxChar
*buf2
=wxRealPath(buf1
);
442 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
444 if (filename
.empty())
447 if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
)))
449 wxString buf
= ::wxGetCwd();
450 wxChar ch
= buf
.Last();
452 if (ch
!= wxT('\\') && ch
!= wxT('/'))
458 buf
<< wxFileFunctionsBuffer
;
459 buf
= wxRealPath( buf
);
460 return MYcopystring( buf
);
462 return MYcopystring( wxFileFunctionsBuffer
);
468 ~user/ => user's home dir
469 If the environment variable a = "foo" and b = "bar" then:
486 /* input name in name, pathname output to buf. */
488 template<typename CharType
>
489 static CharType
*wxDoExpandPath(CharType
*buf
, const wxString
& name
)
491 register CharType
*d
, *s
, *nm
;
492 CharType lnm
[_MAXPATHLEN
];
495 // Some compilers don't like this line.
496 // const CharType trimchars[] = wxT("\n \t");
498 CharType trimchars
[4];
499 trimchars
[0] = wxT('\n');
500 trimchars
[1] = wxT(' ');
501 trimchars
[2] = wxT('\t');
504 static const CharType SEP
= wxFILE_SEP_PATH
;
506 //wxUnix2DosFilename(path);
512 nm
= ::MYcopystring(static_cast<const CharType
*>(name
.c_str())); // Make a scratch copy
513 CharType
*nm_tmp
= nm
;
515 /* Skip leading whitespace and cr */
516 while (wxStrchr(trimchars
, *nm
) != NULL
)
518 /* And strip off trailing whitespace and cr */
519 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
520 while (q
-- && wxStrchr(trimchars
, *s
) != NULL
)
528 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
531 /* Expand inline environment variables */
549 while ((*d
++ = *s
) != 0) {
551 if (*s
== wxT('\\')) {
552 if ((*(d
- 1) = *++s
)!=0) {
560 // No env variables on WinCE
563 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
565 if (*s
++ == wxT('$'))
568 register CharType
*start
= d
;
569 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
570 register CharType
*value
;
571 while ((*d
++ = *s
) != 0)
572 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
577 value
= wxGetenv(braces
? start
+ 1 : start
);
579 for ((d
= start
- 1); (*d
++ = *value
++) != 0;)
593 /* Expand ~ and ~user */
596 if (nm
[0] == wxT('~') && !q
)
599 if (nm
[1] == SEP
|| nm
[1] == 0)
601 homepath
= wxGetUserHome(wxEmptyString
);
602 if (!homepath
.empty()) {
603 s
= (CharType
*)(const CharType
*)homepath
.c_str();
608 { /* ~user/filename */
609 register CharType
*nnm
;
610 for (s
= nm
; *s
&& *s
!= SEP
; s
++)
614 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
615 was_sep
= (*s
== SEP
);
616 nnm
= *s
? s
+ 1 : s
;
618 homepath
= wxGetUserHome(wxString(nm
+ 1));
619 if (homepath
.empty())
621 if (was_sep
) /* replace only if it was there: */
628 s
= (CharType
*)(const CharType
*)homepath
.c_str();
634 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
636 while (wxT('\0') != (*d
++ = *s
++))
639 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
643 while ((*d
++ = *s
++) != 0)
647 delete[] nm_tmp
; // clean up alloc
648 /* Now clean up the buffer */
649 return wxRealPath(buf
);
652 char *wxExpandPath(char *buf
, const wxString
& name
)
654 return wxDoExpandPath(buf
, name
);
657 wchar_t *wxExpandPath(wchar_t *buf
, const wxString
& name
)
659 return wxDoExpandPath(buf
, name
);
663 /* Contract Paths to be build upon an environment variable
666 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
668 The call wxExpandPath can convert these back!
671 wxContractPath (const wxString
& filename
,
672 const wxString
& WXUNUSED_IN_WINCE(envname
),
673 const wxString
& user
)
675 static wxChar dest
[_MAXPATHLEN
];
677 if (filename
.empty())
680 wxStrcpy (dest
, filename
);
682 wxUnix2DosFilename(dest
);
685 // Handle environment
689 if (!envname
.empty() && !(val
= wxGetenv (envname
)).empty() &&
690 (tcp
= wxStrstr (dest
, val
)) != NULL
)
692 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ val
.length());
695 wxStrcpy (tcp
, envname
);
696 wxStrcat (tcp
, wxT("}"));
697 wxStrcat (tcp
, wxFileFunctionsBuffer
);
701 // Handle User's home (ignore root homes!)
702 val
= wxGetUserHome (user
);
706 const size_t len
= val
.length();
710 if (wxStrncmp(dest
, val
, len
) == 0)
712 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
714 wxStrcat(wxFileFunctionsBuffer
, user
);
715 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
716 wxStrcpy (dest
, wxFileFunctionsBuffer
);
722 #endif // #if WXWIN_COMPATIBILITY_2_8
724 // Return just the filename, not the path (basename)
725 wxChar
*wxFileNameFromPath (wxChar
*path
)
728 wxString n
= wxFileNameFromPath(p
);
730 return path
+ p
.length() - n
.length();
733 wxString
wxFileNameFromPath (const wxString
& path
)
735 return wxFileName(path
).GetFullName();
738 // Return just the directory, or NULL if no directory
740 wxPathOnly (wxChar
*path
)
744 static wxChar buf
[_MAXPATHLEN
];
746 int l
= wxStrlen(path
);
748 if ( i
>= _MAXPATHLEN
)
752 wxStrcpy (buf
, path
);
754 // Search backward for a backward or forward slash
757 // Unix like or Windows
758 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
764 if (path
[i
] == wxT(']'))
773 #if defined(__WINDOWS__) || defined(__OS2__)
774 // Try Drive specifier
775 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
777 // A:junk --> A:. (since A:.\junk Not A:\junk)
787 // Return just the directory, or NULL if no directory
788 wxString
wxPathOnly (const wxString
& path
)
792 wxChar buf
[_MAXPATHLEN
];
794 int l
= path
.length();
797 if ( i
>= _MAXPATHLEN
)
803 // Search backward for a backward or forward slash
806 // Unix like or Windows
807 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
809 // Don't return an empty string
813 return wxString(buf
);
816 if (path
[i
] == wxT(']'))
819 return wxString(buf
);
825 #if defined(__WINDOWS__) || defined(__OS2__)
826 // Try Drive specifier
827 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
829 // A:junk --> A:. (since A:.\junk Not A:\junk)
832 return wxString(buf
);
836 return wxEmptyString
;
839 // Utility for converting delimiters in DOS filenames to UNIX style
840 // and back again - or we get nasty problems with delimiters.
841 // Also, convert to lower case, since case is significant in UNIX.
843 #if defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)
845 #define kDefaultPathStyle kCFURLPOSIXPathStyle
847 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
850 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
851 if ( fullURLRef
== NULL
)
852 return wxEmptyString
;
854 if ( additionalPathComponent
)
856 CFURLRef parentURLRef
= fullURLRef
;
857 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
858 additionalPathComponent
,false);
859 CFRelease( parentURLRef
) ;
861 wxCFStringRef
cfString( CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
));
862 CFRelease( fullURLRef
) ;
864 return wxCFStringRef::AsStringWithNormalizationFormC(cfString
);
867 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
869 OSStatus err
= noErr
;
870 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(path
));
871 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
872 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
873 CFRelease( cfMutableString
);
876 if ( CFURLGetFSRef(url
, fsRef
) == false )
887 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
889 wxCFStringRef
cfname( CFStringCreateWithCharacters( kCFAllocatorDefault
,
892 return wxCFStringRef::AsStringWithNormalizationFormC(cfname
);
897 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
900 if ( FSpMakeFSRef( spec
, &fsRef
) == noErr
)
902 return wxMacFSRefToPath( &fsRef
) ;
904 return wxEmptyString
;
907 void wxMacFilename2FSSpec( const wxString
& path
, FSSpec
*spec
)
909 OSStatus err
= noErr
;
911 wxMacPathToFSRef( path
, &fsRef
);
912 err
= FSGetCatalogInfo(&fsRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
920 #if WXWIN_COMPATIBILITY_2_8
923 static void wxDoDos2UnixFilename(T
*s
)
932 *s
= wxTolower(*s
); // Case INDEPENDENT
938 void wxDos2UnixFilename(char *s
) { wxDoDos2UnixFilename(s
); }
939 void wxDos2UnixFilename(wchar_t *s
) { wxDoDos2UnixFilename(s
); }
943 #if defined(__WINDOWS__) || defined(__OS2__)
944 wxDoUnix2DosFilename(T
*s
)
946 wxDoUnix2DosFilename(T
*WXUNUSED(s
) )
949 // Yes, I really mean this to happen under DOS only! JACS
950 #if defined(__WINDOWS__) || defined(__OS2__)
961 void wxUnix2DosFilename(char *s
) { wxDoUnix2DosFilename(s
); }
962 void wxUnix2DosFilename(wchar_t *s
) { wxDoUnix2DosFilename(s
); }
964 #endif // #if WXWIN_COMPATIBILITY_2_8
966 // Concatenate two files to form third
968 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
972 wxFile
in1(file1
), in2(file2
);
973 wxTempFile
out(file3
);
975 if ( !in1
.IsOpened() || !in2
.IsOpened() || !out
.IsOpened() )
979 unsigned char buf
[1024];
981 for( int i
=0; i
<2; i
++)
983 wxFile
*in
= i
==0 ? &in1
: &in2
;
985 if ( (ofs
= in
->Read(buf
,WXSIZEOF(buf
))) == wxInvalidOffset
) return false;
987 if ( !out
.Write(buf
,ofs
) )
989 } while ( ofs
== (ssize_t
)WXSIZEOF(buf
) );
1004 // helper of generic implementation of wxCopyFile()
1005 #if !(defined(__WIN32__) || defined(__OS2__)) && wxUSE_FILE
1008 wxDoCopyFile(wxFile
& fileIn
,
1009 const wxStructStat
& fbuf
,
1010 const wxString
& filenameDst
,
1013 // reset the umask as we want to create the file with exactly the same
1014 // permissions as the original one
1017 // create file2 with the same permissions than file1 and open it for
1021 if ( !fileOut
.Create(filenameDst
, overwrite
, fbuf
.st_mode
& 0777) )
1024 // copy contents of file1 to file2
1028 ssize_t count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1029 if ( count
== wxInvalidOffset
)
1036 if ( fileOut
.Write(buf
, count
) < (size_t)count
)
1040 // we can expect fileIn to be closed successfully, but we should ensure
1041 // that fileOut was closed as some write errors (disk full) might not be
1042 // detected before doing this
1043 return fileIn
.Close() && fileOut
.Close();
1046 #endif // generic implementation of wxCopyFile
1050 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1052 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1053 // CopyFile() copies file attributes and modification time too, so use it
1054 // instead of our code if available
1056 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1057 if ( !::CopyFile(file1
.t_str(), file2
.t_str(), !overwrite
) )
1059 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1060 file1
.c_str(), file2
.c_str());
1064 #elif defined(__OS2__)
1065 if ( ::DosCopy(file1
.c_str(), file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1067 #elif wxUSE_FILE // !Win32
1070 // get permissions of file1
1071 if ( wxStat( file1
, &fbuf
) != 0 )
1073 // the file probably doesn't exist or we haven't the rights to read
1075 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1080 // open file1 for reading
1081 wxFile
fileIn(file1
, wxFile::read
);
1082 if ( !fileIn
.IsOpened() )
1085 // remove file2, if it exists. This is needed for creating
1086 // file2 with the correct permissions in the next step
1087 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1089 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1094 wxDoCopyFile(fileIn
, fbuf
, file2
, overwrite
);
1096 #if defined(__WXMAC__) || defined(__WXCOCOA__)
1097 // copy the resource fork of the file too if it's present
1098 wxString pathRsrcOut
;
1102 // suppress error messages from this block as resource forks don't have
1106 // it's not enough to check for file existence: it always does on HFS
1107 // but is empty for files without resources
1108 if ( fileRsrcIn
.Open(file1
+ wxT("/..namedfork/rsrc")) &&
1109 fileRsrcIn
.Length() > 0 )
1111 // we must be using HFS or another filesystem with resource fork
1112 // support, suppose that destination file system also is HFS[-like]
1113 pathRsrcOut
= file2
+ wxT("/..namedfork/rsrc");
1115 else // check if we have resource fork in separate file (non-HFS case)
1117 wxFileName
fnRsrc(file1
);
1118 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1121 if ( fileRsrcIn
.Open( fnRsrc
.GetFullPath() ) )
1124 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1126 pathRsrcOut
= fnRsrc
.GetFullPath();
1131 if ( !pathRsrcOut
.empty() )
1133 if ( !wxDoCopyFile(fileRsrcIn
, fbuf
, pathRsrcOut
, overwrite
) )
1136 #endif // wxMac || wxCocoa
1138 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1139 // no chmod in VA. Should be some permission API for HPFS386 partitions
1141 if ( chmod(file2
.fn_str(), fbuf
.st_mode
) != 0 )
1143 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1147 #endif // OS/2 || Mac
1149 #else // !Win32 && ! wxUSE_FILE
1151 // impossible to simulate with wxWidgets API
1154 wxUnusedVar(overwrite
);
1157 #endif // __WINDOWS__ && __WIN32__
1163 wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1165 if ( !overwrite
&& wxFileExists(file2
) )
1169 _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
1170 file1
.c_str(), file2
.c_str()
1176 #if !defined(__WXWINCE__)
1177 // Normal system call
1178 if ( wxRename (file1
, file2
) == 0 )
1183 if (wxCopyFile(file1
, file2
, overwrite
)) {
1184 wxRemoveFile(file1
);
1188 wxLogSysError(_("File '%s' couldn't be renamed '%s'"), file1
, file2
);
1192 bool wxRemoveFile(const wxString
& file
)
1194 #if defined(__VISUALC__) \
1195 || defined(__BORLANDC__) \
1196 || defined(__WATCOMC__) \
1197 || defined(__DMC__) \
1198 || defined(__GNUWIN32__)
1199 int res
= wxRemove(file
);
1200 #elif defined(__WXMAC__)
1201 int res
= unlink(file
.fn_str());
1203 int res
= unlink(file
.fn_str());
1207 wxLogSysError(_("File '%s' couldn't be removed"), file
);
1212 bool wxMkdir(const wxString
& dir
, int perm
)
1214 #if defined(__WXMAC__) && !defined(__UNIX__)
1215 if ( mkdir(dir
.fn_str(), 0) != 0 )
1217 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1218 // for the GNU compiler
1219 #elif (!(defined(__WINDOWS__) || defined(__OS2__) || defined(__DOS__))) || \
1220 (defined(__GNUWIN32__) && !defined(__MINGW32__)) || \
1221 defined(__WINE__) || defined(__WXMICROWIN__)
1222 const wxChar
*dirname
= dir
.c_str();
1225 if ( mkdir(wxFNCONV(dirname
)) != 0 )
1227 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1229 #elif defined(__OS2__)
1231 if (::DosCreateDir(dir
.c_str(), NULL
) != 0) // enhance for EAB's??
1232 #elif defined(__DOS__)
1233 const wxChar
*dirname
= dir
.c_str();
1234 #if defined(__WATCOMC__)
1236 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1237 #elif defined(__DJGPP__)
1238 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1240 #error "Unsupported DOS compiler!"
1242 #else // !MSW, !DOS and !OS/2 VAC++
1245 if ( CreateDirectory(dir
.fn_str(), NULL
) == 0 )
1247 if ( wxMkDir(dir
.fn_str()) != 0 )
1251 wxLogSysError(_("Directory '%s' couldn't be created"), dir
);
1258 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1260 #if defined(__VMS__)
1261 return false; //to be changed since rmdir exists in VMS7.x
1263 #if defined(__OS2__)
1264 if ( ::DosDeleteDir(dir
.c_str()) != 0 )
1265 #elif defined(__WXWINCE__)
1266 if ( RemoveDirectory(dir
.fn_str()) == 0 )
1268 if ( wxRmDir(dir
.fn_str()) != 0 )
1271 wxLogSysError(_("Directory '%s' couldn't be deleted"), dir
);
1279 // does the path exists? (may have or not '/' or '\\' at the end)
1280 bool wxDirExists(const wxString
& pathName
)
1282 return wxFileName::DirExists(pathName
);
1285 #if WXWIN_COMPATIBILITY_2_8
1287 // Get a temporary filename, opening and closing the file.
1288 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1291 if ( !wxGetTempFileName(prefix
, filename
) )
1295 wxStrcpy(buf
, filename
);
1297 buf
= MYcopystring(filename
);
1302 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1305 buf
= wxFileName::CreateTempFileName(prefix
);
1307 return !buf
.empty();
1308 #else // !wxUSE_FILE
1309 wxUnusedVar(prefix
);
1313 #endif // wxUSE_FILE/!wxUSE_FILE
1316 #endif // #if WXWIN_COMPATIBILITY_2_8
1318 // Get first file name matching given wild card.
1320 static wxDir
*gs_dir
= NULL
;
1321 static wxString gs_dirPath
;
1323 wxString
wxFindFirstFile(const wxString
& spec
, int flags
)
1325 wxFileName::SplitPath(spec
, &gs_dirPath
, NULL
, NULL
);
1326 if ( gs_dirPath
.empty() )
1327 gs_dirPath
= wxT(".");
1328 if ( !wxEndsWithPathSeparator(gs_dirPath
) )
1329 gs_dirPath
<< wxFILE_SEP_PATH
;
1331 delete gs_dir
; // can be NULL, this is ok
1332 gs_dir
= new wxDir(gs_dirPath
);
1334 if ( !gs_dir
->IsOpened() )
1336 wxLogSysError(_("Cannot enumerate files '%s'"), spec
);
1337 return wxEmptyString
;
1343 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1344 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1345 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1349 gs_dir
->GetFirst(&result
, wxFileNameFromPath(spec
), dirFlags
);
1350 if ( result
.empty() )
1356 return gs_dirPath
+ result
;
1359 wxString
wxFindNextFile()
1361 wxCHECK_MSG( gs_dir
, "", "You must call wxFindFirstFile before!" );
1364 if ( !gs_dir
->GetNext(&result
) || result
.empty() )
1370 return gs_dirPath
+ result
;
1374 // Get current working directory.
1375 // If buf is NULL, allocates space using new, else copies into buf.
1376 // wxGetWorkingDirectory() is obsolete, use wxGetCwd()
1377 // wxDoGetCwd() is their common core to be moved
1378 // to wxGetCwd() once wxGetWorkingDirectory() will be removed.
1379 // Do not expose wxDoGetCwd in headers!
1381 wxChar
*wxDoGetCwd(wxChar
*buf
, int sz
)
1383 #if defined(__WXWINCE__)
1385 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1390 buf
= new wxChar
[sz
+ 1];
1395 // for the compilers which have Unicode version of _getcwd(), call it
1396 // directly, for the others call the ANSI version and do the translation
1399 #else // wxUSE_UNICODE
1400 bool needsANSI
= true;
1402 #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
1403 char cbuf
[_MAXPATHLEN
];
1407 #if wxUSE_UNICODE_MSLU
1408 if ( wxGetOsVersion() != wxOS_WINDOWS_9X
)
1410 char *cbuf
= NULL
; // never really used because needsANSI will always be false
1413 ok
= _wgetcwd(buf
, sz
) != NULL
;
1419 #endif // wxUSE_UNICODE
1421 #if defined(_MSC_VER) || defined(__MINGW32__)
1422 ok
= _getcwd(cbuf
, sz
) != NULL
;
1423 #elif defined(__OS2__)
1425 ULONG ulDriveNum
= 0;
1426 ULONG ulDriveMap
= 0;
1427 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
1432 rc
= ::DosQueryCurrentDir( 0 // current drive
1436 cbuf
[0] = char('A' + (ulDriveNum
- 1));
1441 #else // !Win32/VC++ !Mac !OS2
1442 ok
= getcwd(cbuf
, sz
) != NULL
;
1446 // finally convert the result to Unicode if needed
1447 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1448 #endif // wxUSE_UNICODE
1453 wxLogSysError(_("Failed to get the working directory"));
1455 // VZ: the old code used to return "." on error which didn't make any
1456 // sense at all to me - empty string is a better error indicator
1457 // (NULL might be even better but I'm afraid this could lead to
1458 // problems with the old code assuming the return is never NULL)
1461 else // ok, but we might need to massage the path into the right format
1464 // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
1465 // with / deliminers. We don't like that.
1466 for (wxChar
*ch
= buf
; *ch
; ch
++)
1468 if (*ch
== wxT('/'))
1473 // MBN: we hope that in the case the user is compiling a GTK+/Motif app,
1474 // he needs Unix as opposed to Win32 pathnames
1475 #if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
1476 // another example of DOS/Unix mix (Cygwin)
1477 wxString pathUnix
= buf
;
1479 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1480 cygwin_conv_path(CCP_POSIX_TO_WIN_W
, pathUnix
.mb_str(wxConvFile
), buf
, sz
);
1482 char bufA
[_MAXPATHLEN
];
1483 cygwin_conv_to_full_win32_path(pathUnix
.mb_str(wxConvFile
), bufA
);
1484 wxConvFile
.MB2WC(buf
, bufA
, sz
);
1487 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1488 cygwin_conv_path(CCP_POSIX_TO_WIN_A
, pathUnix
, buf
, sz
);
1490 cygwin_conv_to_full_win32_path(pathUnix
, buf
);
1492 #endif // wxUSE_UNICODE
1493 #endif // __CYGWIN__
1506 #if WXWIN_COMPATIBILITY_2_6
1507 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1509 return wxDoGetCwd(buf
,sz
);
1511 #endif // WXWIN_COMPATIBILITY_2_6
1516 wxDoGetCwd(wxStringBuffer(str
, _MAXPATHLEN
), _MAXPATHLEN
);
1520 bool wxSetWorkingDirectory(const wxString
& d
)
1522 bool success
= false;
1523 #if defined(__OS2__)
1526 ::DosSetDefaultDisk(wxToupper(d
[0]) - wxT('A') + 1);
1527 // do not call DosSetCurrentDir when just changing drive,
1528 // since it requires e.g. "d:." instead of "d:"!
1529 if (d
.length() == 2)
1532 success
= (::DosSetCurrentDir(d
.c_str()) == 0);
1533 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1534 success
= (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1535 #elif defined(__WINDOWS__)
1539 // No equivalent in WinCE
1542 success
= (SetCurrentDirectory(d
.t_str()) != 0);
1545 // Must change drive, too.
1546 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1549 wxChar firstChar
= d
[0];
1553 firstChar
= firstChar
- 32;
1555 // To a drive number
1556 unsigned int driveNo
= firstChar
- 64;
1559 unsigned int noDrives
;
1560 _dos_setdrive(driveNo
, &noDrives
);
1563 success
= (chdir(WXSTRINGCAST d
) == 0);
1569 wxLogSysError(_("Could not set current working directory"));
1574 // Get the OS directory if appropriate (such as the Windows directory).
1575 // On non-Windows platform, probably just return the empty string.
1576 wxString
wxGetOSDirectory()
1579 return wxString(wxT("\\Windows"));
1580 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1581 wxChar buf
[MAX_PATH
];
1582 if ( !GetWindowsDirectory(buf
, MAX_PATH
) )
1584 wxLogLastError(wxS("GetWindowsDirectory"));
1587 return wxString(buf
);
1588 #elif defined(__WXMAC__) && wxOSX_USE_CARBON
1589 return wxMacFindFolderNoSeparator(kOnSystemDisk
, 'macs', false);
1591 return wxEmptyString
;
1595 bool wxEndsWithPathSeparator(const wxString
& filename
)
1597 return !filename
.empty() && wxIsPathSeparator(filename
.Last());
1600 // find a file in a list of directories, returns false if not found
1601 bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
)
1603 // we assume that it's not empty
1604 wxCHECK_MSG( !szFile
.empty(), false,
1605 wxT("empty file name in wxFindFileInPath"));
1607 // skip path separator in the beginning of the file name if present
1609 if ( wxIsPathSeparator(szFile
[0u]) )
1610 szFile2
= szFile
.Mid(1);
1614 wxStringTokenizer
tkn(szPath
, wxPATH_SEP
);
1616 while ( tkn
.HasMoreTokens() )
1618 wxString strFile
= tkn
.GetNextToken();
1619 if ( !wxEndsWithPathSeparator(strFile
) )
1620 strFile
+= wxFILE_SEP_PATH
;
1623 if ( wxFileExists(strFile
) )
1633 #if WXWIN_COMPATIBILITY_2_8
1634 void WXDLLIMPEXP_BASE
wxSplitPath(const wxString
& fileName
,
1639 wxFileName::SplitPath(fileName
, pstrPath
, pstrName
, pstrExt
);
1641 #endif // #if WXWIN_COMPATIBILITY_2_8
1645 time_t WXDLLIMPEXP_BASE
wxFileModificationTime(const wxString
& filename
)
1648 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1651 return mtime
.GetTicks();
1654 #endif // wxUSE_DATETIME
1657 // Parses the filterStr, returning the number of filters.
1658 // Returns 0 if none or if there's a problem.
1659 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1661 int WXDLLIMPEXP_BASE
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1662 wxArrayString
& descriptions
,
1663 wxArrayString
& filters
)
1665 descriptions
.Clear();
1668 wxString
str(filterStr
);
1670 wxString description
, filter
;
1672 while( pos
!= wxNOT_FOUND
)
1674 pos
= str
.Find(wxT('|'));
1675 if ( pos
== wxNOT_FOUND
)
1677 // if there are no '|'s at all in the string just take the entire
1678 // string as filter and make description empty for later autocompletion
1679 if ( filters
.IsEmpty() )
1681 descriptions
.Add(wxEmptyString
);
1682 filters
.Add(filterStr
);
1686 wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
1692 description
= str
.Left(pos
);
1693 str
= str
.Mid(pos
+ 1);
1694 pos
= str
.Find(wxT('|'));
1695 if ( pos
== wxNOT_FOUND
)
1701 filter
= str
.Left(pos
);
1702 str
= str
.Mid(pos
+ 1);
1705 descriptions
.Add(description
);
1706 filters
.Add(filter
);
1709 #if defined(__WXMOTIF__)
1710 // split it so there is one wildcard per entry
1711 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1713 pos
= filters
[i
].Find(wxT(';'));
1714 if (pos
!= wxNOT_FOUND
)
1716 // first split only filters
1717 descriptions
.Insert(descriptions
[i
],i
+1);
1718 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1719 filters
[i
]=filters
[i
].Left(pos
);
1721 // autoreplace new filter in description with pattern:
1722 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1723 // cause split into:
1724 // C/C++ Files(*.cpp)|*.cpp
1725 // C/C++ Files(*.c;*.h)|*.c;*.h
1726 // and next iteration cause another split into:
1727 // C/C++ Files(*.cpp)|*.cpp
1728 // C/C++ Files(*.c)|*.c
1729 // C/C++ Files(*.h)|*.h
1730 for ( size_t k
=i
;k
<i
+2;k
++ )
1732 pos
= descriptions
[k
].Find(filters
[k
]);
1733 if (pos
!= wxNOT_FOUND
)
1735 wxString before
= descriptions
[k
].Left(pos
);
1736 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1737 pos
= before
.Find(wxT('('),true);
1738 if (pos
>before
.Find(wxT(')'),true))
1740 before
= before
.Left(pos
+1);
1741 before
<< filters
[k
];
1742 pos
= after
.Find(wxT(')'));
1743 int pos1
= after
.Find(wxT('('));
1744 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1746 before
<< after
.Mid(pos
);
1747 descriptions
[k
] = before
;
1757 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1759 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1761 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1765 return filters
.GetCount();
1768 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1769 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1771 // quoting the MSDN: "To obtain a handle to a directory, call the
1772 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1773 // doesn't work under Win9x/ME but then it's not needed there anyhow
1774 const DWORD dwAttr
= ::GetFileAttributes(path
.t_str());
1775 if ( dwAttr
== INVALID_FILE_ATTRIBUTES
)
1777 // file probably doesn't exist at all
1781 if ( wxGetOsVersion() == wxOS_WINDOWS_9X
)
1783 // FAT directories always allow all access, even if they have the
1784 // readonly flag set, and FAT files can only be read-only
1785 return (dwAttr
& FILE_ATTRIBUTE_DIRECTORY
) ||
1786 (access
!= GENERIC_WRITE
||
1787 !(dwAttr
& FILE_ATTRIBUTE_READONLY
));
1790 HANDLE h
= ::CreateFile
1794 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1797 dwAttr
& FILE_ATTRIBUTE_DIRECTORY
1798 ? FILE_FLAG_BACKUP_SEMANTICS
1802 if ( h
!= INVALID_HANDLE_VALUE
)
1805 return h
!= INVALID_HANDLE_VALUE
;
1807 #endif // __WINDOWS__
1809 bool wxIsWritable(const wxString
&path
)
1811 #if defined( __UNIX__ ) || defined(__OS2__)
1812 // access() will take in count also symbolic links
1813 return wxAccess(path
.c_str(), W_OK
) == 0;
1814 #elif defined( __WINDOWS__ )
1815 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1823 bool wxIsReadable(const wxString
&path
)
1825 #if defined( __UNIX__ ) || defined(__OS2__)
1826 // access() will take in count also symbolic links
1827 return wxAccess(path
.c_str(), R_OK
) == 0;
1828 #elif defined( __WINDOWS__ )
1829 return wxCheckWin32Permission(path
, GENERIC_READ
);
1837 bool wxIsExecutable(const wxString
&path
)
1839 #if defined( __UNIX__ ) || defined(__OS2__)
1840 // access() will take in count also symbolic links
1841 return wxAccess(path
.c_str(), X_OK
) == 0;
1842 #elif defined( __WINDOWS__ )
1843 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1851 // Return the type of an open file
1853 // Some file types on some platforms seem seekable but in fact are not.
1854 // The main use of this function is to allow such cases to be detected
1855 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1857 // This is important for the archive streams, which benefit greatly from
1858 // being able to seek on a stream, but which will produce corrupt archives
1859 // if they unknowingly seek on a non-seekable stream.
1861 // wxFILE_KIND_DISK is a good catch all return value, since other values
1862 // disable features of the archive streams. Some other value must be returned
1863 // for a file type that appears seekable but isn't.
1866 // * Pipes on Windows
1867 // * Files on VMS with a record format other than StreamLF
1869 wxFileKind
wxGetFileKind(int fd
)
1871 #if defined __WINDOWS__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1872 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1874 case FILE_TYPE_CHAR
:
1875 return wxFILE_KIND_TERMINAL
;
1876 case FILE_TYPE_DISK
:
1877 return wxFILE_KIND_DISK
;
1878 case FILE_TYPE_PIPE
:
1879 return wxFILE_KIND_PIPE
;
1882 return wxFILE_KIND_UNKNOWN
;
1884 #elif defined(__UNIX__)
1886 return wxFILE_KIND_TERMINAL
;
1891 if (S_ISFIFO(st
.st_mode
))
1892 return wxFILE_KIND_PIPE
;
1893 if (!S_ISREG(st
.st_mode
))
1894 return wxFILE_KIND_UNKNOWN
;
1896 #if defined(__VMS__)
1897 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1898 return wxFILE_KIND_UNKNOWN
;
1901 return wxFILE_KIND_DISK
;
1904 #define wxFILEKIND_STUB
1906 return wxFILE_KIND_DISK
;
1910 wxFileKind
wxGetFileKind(FILE *fp
)
1912 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1913 // Should be fixed in version 1.4.
1914 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1916 return wxFILE_KIND_DISK
;
1917 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WINE__)
1918 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1920 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1925 //------------------------------------------------------------------------
1926 // wild character routines
1927 //------------------------------------------------------------------------
1929 bool wxIsWild( const wxString
& pattern
)
1931 for ( wxString::const_iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
)
1933 switch ( (*p
).GetValue() )
1942 if ( ++p
== pattern
.end() )
1950 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1952 * The match procedure is public domain code (from ircII's reg.c)
1953 * but modified to suit our tastes (RN: No "%" syntax I guess)
1956 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1960 /* Match if both are empty. */
1964 const wxChar
*m
= pat
.c_str(),
1972 if (dot_special
&& (*n
== wxT('.')))
1974 /* Never match so that hidden Unix files
1975 * are never found. */
1988 else if (*m
== wxT('?'))
1996 if (*m
== wxT('\\'))
1999 /* Quoting "nothing" is a bad thing */
2006 * If we are out of both strings or we just
2007 * saw a wildcard, then we can say we have a
2018 * We could check for *n == NULL at this point, but
2019 * since it's more common to have a character there,
2020 * check to see if they match first (m and n) and
2021 * then if they don't match, THEN we can check for
2037 * If there are no more characters in the
2038 * string, but we still need to find another
2039 * character (*m != NULL), then it will be
2040 * impossible to match it
2059 #pragma warning(default:4706) // assignment within conditional expression