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()
67 // and for cygwin_conv_path()
69 // note that it must be included after <windows.h>
72 #include <sys/cygwin.h>
73 #include <cygwin/version.h>
75 #endif // __GNUWIN32__
77 // io.h is needed for _get_osfhandle()
78 // Already included by filefn.h for many Windows compilers
79 #if defined __MWERKS__ || defined __CYGWIN__
88 // TODO: Borland probably has _wgetcwd as well?
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
98 #define _MAXPATHLEN 1024
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 #if WXWIN_COMPATIBILITY_2_8
106 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
109 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
111 // VisualAge C++ V4.0 cannot have any external linkage const decs
112 // in headers included by more than one primary source
114 const int wxInvalidOffset
= -1;
117 // ============================================================================
119 // ============================================================================
121 // ----------------------------------------------------------------------------
122 // wrappers around standard POSIX functions
123 // ----------------------------------------------------------------------------
125 #if wxUSE_UNICODE && defined __BORLANDC__ \
126 && __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
128 // BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
129 // regardless of the mode parameter. This hack works around the problem by
130 // setting the mode with _wchmod.
132 int wxCRT_OpenW(const wchar_t *pathname
, int flags
, mode_t mode
)
136 // we only want to fix the mode when the file is actually created, so
137 // when creating first try doing it O_EXCL so we can tell if the file
138 // was already there.
139 if ((flags
& O_CREAT
) && !(flags
& O_EXCL
) && (mode
& wxS_IWUSR
) != 0)
142 int fd
= _wopen(pathname
, flags
| moreflags
, mode
);
144 // the file was actually created and needs fixing
145 if (fd
!= -1 && (flags
& O_CREAT
) != 0 && (mode
& wxS_IWUSR
) != 0)
148 _wchmod(pathname
, mode
);
149 fd
= _wopen(pathname
, flags
& ~(O_EXCL
| O_CREAT
));
151 // the open failed, but it may have been because the added O_EXCL stopped
152 // the opening of an existing file, so try again without.
153 else if (fd
== -1 && moreflags
!= 0)
155 fd
= _wopen(pathname
, flags
& ~O_CREAT
);
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 bool wxPathList::Add(const wxString
& path
)
169 // add a path separator to force wxFileName to interpret it always as a directory
170 // (i.e. if we are called with '/home/user' we want to consider it a folder and
171 // not, as wxFileName would consider, a filename).
172 wxFileName
fn(path
+ wxFileName::GetPathSeparator());
174 // add only normalized relative/absolute paths
175 // NB: we won't do wxPATH_NORM_DOTS in order to avoid problems when trying to
176 // normalize paths which starts with ".." (which can be normalized only if
177 // we use also wxPATH_NORM_ABSOLUTE - which we don't want to use).
178 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
181 wxString toadd
= fn
.GetPath();
182 if (Index(toadd
) == wxNOT_FOUND
)
183 wxArrayString::Add(toadd
); // do not add duplicates
188 void wxPathList::Add(const wxArrayString
&arr
)
190 for (size_t j
=0; j
< arr
.GetCount(); j
++)
194 // Add paths e.g. from the PATH environment variable
195 void wxPathList::AddEnvList (const wxString
& WXUNUSED_IN_WINCE(envVariable
))
197 // No environment variables on WinCE
200 // The space has been removed from the tokenizers, otherwise a
201 // path such as "C:\Program Files" would be split into 2 paths:
202 // "C:\Program" and "Files"; this is true for both Windows and Unix.
204 static const wxChar PATH_TOKS
[] =
205 #if defined(__WINDOWS__) || defined(__OS2__)
206 wxT(";"); // Don't separate with colon in DOS (used for drive)
212 if ( wxGetEnv(envVariable
, &val
) )
214 // split into an array of string the value of the env var
215 wxArrayString arr
= wxStringTokenize(val
, PATH_TOKS
);
216 WX_APPEND_ARRAY(*this, arr
);
218 #endif // !__WXWINCE__
221 // Given a full filename (with path), ensure that that file can
222 // be accessed again USING FILENAME ONLY by adding the path
223 // to the list if not already there.
224 bool wxPathList::EnsureFileAccessible (const wxString
& path
)
226 return Add(wxPathOnly(path
));
229 #if WXWIN_COMPATIBILITY_2_6
230 bool wxPathList::Member (const wxString
& path
) const
232 return Index(path
) != wxNOT_FOUND
;
236 wxString
wxPathList::FindValidPath (const wxString
& file
) const
238 // normalize the given string as it could be a path + a filename
239 // and not only a filename
243 // NB: normalize without making absolute otherwise calling this function with
244 // e.g. "b/c.txt" would result in removing the directory 'b' and the for loop
245 // below would only add to the paths of this list the 'c.txt' part when doing
246 // the existence checks...
247 // NB: we don't use wxPATH_NORM_DOTS here, too (see wxPathList::Add for more info)
248 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
249 return wxEmptyString
;
251 wxASSERT_MSG(!fn
.IsDir(), wxT("Cannot search for directories; only for files"));
253 strend
= fn
.GetFullName(); // search for the file name and ignore the path part
255 strend
= fn
.GetFullPath();
257 for (size_t i
=0; i
<GetCount(); i
++)
259 wxString strstart
= Item(i
);
260 if (!strstart
.IsEmpty() && strstart
.Last() != wxFileName::GetPathSeparator())
261 strstart
+= wxFileName::GetPathSeparator();
263 if (wxFileExists(strstart
+ strend
))
264 return strstart
+ strend
; // Found!
267 return wxEmptyString
; // Not found
270 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
) const
272 wxString f
= FindValidPath(file
);
273 if ( f
.empty() || wxIsAbsolutePath(f
) )
276 wxString buf
= ::wxGetCwd();
278 if ( !wxEndsWithPathSeparator(buf
) )
280 buf
+= wxFILE_SEP_PATH
;
287 // ----------------------------------------------------------------------------
288 // miscellaneous global functions
289 // ----------------------------------------------------------------------------
291 #if WXWIN_COMPATIBILITY_2_8
292 static inline wxChar
* MYcopystring(const wxString
& s
)
294 wxChar
* copy
= new wxChar
[s
.length() + 1];
295 return wxStrcpy(copy
, s
.c_str());
298 template<typename CharType
>
299 static inline CharType
* MYcopystring(const CharType
* s
)
301 CharType
* copy
= new CharType
[wxStrlen(s
) + 1];
302 return wxStrcpy(copy
, s
);
308 wxFileExists (const wxString
& filename
)
310 return wxFileName::FileExists(filename
);
314 wxIsAbsolutePath (const wxString
& filename
)
316 if (!filename
.empty())
318 // Unix like or Windows
319 if (filename
[0] == wxT('/'))
322 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
325 #if defined(__WINDOWS__) || defined(__OS2__)
327 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
334 #if WXWIN_COMPATIBILITY_2_8
336 * Strip off any extension (dot something) from end of file,
337 * IF one exists. Inserts zero into buffer.
342 static void wxDoStripExtension(T
*buffer
)
344 int len
= wxStrlen(buffer
);
348 if (buffer
[i
] == wxT('.'))
357 void wxStripExtension(char *buffer
) { wxDoStripExtension(buffer
); }
358 void wxStripExtension(wchar_t *buffer
) { wxDoStripExtension(buffer
); }
360 void wxStripExtension(wxString
& buffer
)
362 buffer
= wxFileName::StripExtension(buffer
);
365 // Destructive removal of /./ and /../ stuff
366 template<typename CharType
>
367 static CharType
*wxDoRealPath (CharType
*path
)
369 static const CharType SEP
= wxFILE_SEP_PATH
;
371 wxUnix2DosFilename(path
);
373 if (path
[0] && path
[1]) {
374 /* MATTHEW: special case "/./x" */
376 if (path
[2] == SEP
&& path
[1] == wxT('.'))
384 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
387 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--)
392 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
393 && (q
- 1 <= path
|| q
[-1] != SEP
))
396 if (path
[0] == wxT('\0'))
401 #if defined(__WXMSW__) || defined(__OS2__)
402 /* Check that path[2] is NULL! */
403 else if (path
[1] == wxT(':') && !path
[2])
412 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
420 char *wxRealPath(char *path
)
422 return wxDoRealPath(path
);
425 wchar_t *wxRealPath(wchar_t *path
)
427 return wxDoRealPath(path
);
430 wxString
wxRealPath(const wxString
& path
)
432 wxChar
*buf1
=MYcopystring(path
);
433 wxChar
*buf2
=wxRealPath(buf1
);
441 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
443 if (filename
.empty())
446 if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
)))
448 wxString buf
= ::wxGetCwd();
449 wxChar ch
= buf
.Last();
451 if (ch
!= wxT('\\') && ch
!= wxT('/'))
457 buf
<< wxFileFunctionsBuffer
;
458 buf
= wxRealPath( buf
);
459 return MYcopystring( buf
);
461 return MYcopystring( wxFileFunctionsBuffer
);
467 ~user/ => user's home dir
468 If the environment variable a = "foo" and b = "bar" then:
485 /* input name in name, pathname output to buf. */
487 template<typename CharType
>
488 static CharType
*wxDoExpandPath(CharType
*buf
, const wxString
& name
)
490 register CharType
*d
, *s
, *nm
;
491 CharType lnm
[_MAXPATHLEN
];
494 // Some compilers don't like this line.
495 // const CharType trimchars[] = wxT("\n \t");
497 CharType trimchars
[4];
498 trimchars
[0] = wxT('\n');
499 trimchars
[1] = wxT(' ');
500 trimchars
[2] = wxT('\t');
503 static const CharType SEP
= wxFILE_SEP_PATH
;
505 //wxUnix2DosFilename(path);
511 nm
= ::MYcopystring(static_cast<const CharType
*>(name
.c_str())); // Make a scratch copy
512 CharType
*nm_tmp
= nm
;
514 /* Skip leading whitespace and cr */
515 while (wxStrchr(trimchars
, *nm
) != NULL
)
517 /* And strip off trailing whitespace and cr */
518 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
519 while (q
-- && wxStrchr(trimchars
, *s
) != NULL
)
527 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
530 /* Expand inline environment variables */
548 while ((*d
++ = *s
) != 0) {
550 if (*s
== wxT('\\')) {
551 if ((*(d
- 1) = *++s
)!=0) {
559 // No env variables on WinCE
562 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
564 if (*s
++ == wxT('$'))
567 register CharType
*start
= d
;
568 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
569 register CharType
*value
;
570 while ((*d
++ = *s
) != 0)
571 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
576 value
= wxGetenv(braces
? start
+ 1 : start
);
578 for ((d
= start
- 1); (*d
++ = *value
++) != 0;)
592 /* Expand ~ and ~user */
595 if (nm
[0] == wxT('~') && !q
)
598 if (nm
[1] == SEP
|| nm
[1] == 0)
600 homepath
= wxGetUserHome(wxEmptyString
);
601 if (!homepath
.empty()) {
602 s
= (CharType
*)(const CharType
*)homepath
.c_str();
607 { /* ~user/filename */
608 register CharType
*nnm
;
609 for (s
= nm
; *s
&& *s
!= SEP
; s
++)
613 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
614 was_sep
= (*s
== SEP
);
615 nnm
= *s
? s
+ 1 : s
;
617 homepath
= wxGetUserHome(wxString(nm
+ 1));
618 if (homepath
.empty())
620 if (was_sep
) /* replace only if it was there: */
627 s
= (CharType
*)(const CharType
*)homepath
.c_str();
633 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
635 while (wxT('\0') != (*d
++ = *s
++))
638 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
642 while ((*d
++ = *s
++) != 0)
646 delete[] nm_tmp
; // clean up alloc
647 /* Now clean up the buffer */
648 return wxRealPath(buf
);
651 char *wxExpandPath(char *buf
, const wxString
& name
)
653 return wxDoExpandPath(buf
, name
);
656 wchar_t *wxExpandPath(wchar_t *buf
, const wxString
& name
)
658 return wxDoExpandPath(buf
, name
);
662 /* Contract Paths to be build upon an environment variable
665 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
667 The call wxExpandPath can convert these back!
670 wxContractPath (const wxString
& filename
,
671 const wxString
& WXUNUSED_IN_WINCE(envname
),
672 const wxString
& user
)
674 static wxChar dest
[_MAXPATHLEN
];
676 if (filename
.empty())
679 wxStrcpy (dest
, filename
);
681 wxUnix2DosFilename(dest
);
684 // Handle environment
688 if (!envname
.empty() && !(val
= wxGetenv (envname
)).empty() &&
689 (tcp
= wxStrstr (dest
, val
)) != NULL
)
691 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ val
.length());
694 wxStrcpy (tcp
, envname
);
695 wxStrcat (tcp
, wxT("}"));
696 wxStrcat (tcp
, wxFileFunctionsBuffer
);
700 // Handle User's home (ignore root homes!)
701 val
= wxGetUserHome (user
);
705 const size_t len
= val
.length();
709 if (wxStrncmp(dest
, val
, len
) == 0)
711 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
713 wxStrcat(wxFileFunctionsBuffer
, user
);
714 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
715 wxStrcpy (dest
, wxFileFunctionsBuffer
);
721 #endif // #if WXWIN_COMPATIBILITY_2_8
723 // Return just the filename, not the path (basename)
724 wxChar
*wxFileNameFromPath (wxChar
*path
)
727 wxString n
= wxFileNameFromPath(p
);
729 return path
+ p
.length() - n
.length();
732 wxString
wxFileNameFromPath (const wxString
& path
)
734 return wxFileName(path
).GetFullName();
737 // Return just the directory, or NULL if no directory
739 wxPathOnly (wxChar
*path
)
743 static wxChar buf
[_MAXPATHLEN
];
746 wxStrcpy (buf
, path
);
748 int l
= wxStrlen(path
);
751 // Search backward for a backward or forward slash
754 // Unix like or Windows
755 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
761 if (path
[i
] == wxT(']'))
770 #if defined(__WXMSW__) || defined(__OS2__)
771 // Try Drive specifier
772 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
774 // A:junk --> A:. (since A:.\junk Not A:\junk)
784 // Return just the directory, or NULL if no directory
785 wxString
wxPathOnly (const wxString
& path
)
789 wxChar buf
[_MAXPATHLEN
];
794 int l
= path
.length();
797 // Search backward for a backward or forward slash
800 // Unix like or Windows
801 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
803 // Don't return an empty string
807 return wxString(buf
);
810 if (path
[i
] == wxT(']'))
813 return wxString(buf
);
819 #if defined(__WXMSW__) || defined(__OS2__)
820 // Try Drive specifier
821 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
823 // A:junk --> A:. (since A:.\junk Not A:\junk)
826 return wxString(buf
);
830 return wxEmptyString
;
833 // Utility for converting delimiters in DOS filenames to UNIX style
834 // and back again - or we get nasty problems with delimiters.
835 // Also, convert to lower case, since case is significant in UNIX.
837 #if defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)
839 #define kDefaultPathStyle kCFURLPOSIXPathStyle
841 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
844 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
845 if ( additionalPathComponent
)
847 CFURLRef parentURLRef
= fullURLRef
;
848 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
849 additionalPathComponent
,false);
850 CFRelease( parentURLRef
) ;
852 CFStringRef cfString
= CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
);
853 CFRelease( fullURLRef
) ;
854 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfString
);
855 CFRelease( cfString
);
856 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
857 return wxCFStringRef(cfMutableString
).AsString();
860 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
862 OSStatus err
= noErr
;
863 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(path
));
864 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
865 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
866 CFRelease( cfMutableString
);
869 if ( CFURLGetFSRef(url
, fsRef
) == false )
880 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
882 CFStringRef cfname
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
885 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfname
);
887 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
888 return wxCFStringRef(cfMutableString
).AsString() ;
893 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
896 if ( FSpMakeFSRef( spec
, &fsRef
) == noErr
)
898 return wxMacFSRefToPath( &fsRef
) ;
900 return wxEmptyString
;
903 void wxMacFilename2FSSpec( const wxString
& path
, FSSpec
*spec
)
905 OSStatus err
= noErr
;
907 wxMacPathToFSRef( path
, &fsRef
);
908 err
= FSGetCatalogInfo(&fsRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
916 #if WXWIN_COMPATIBILITY_2_8
919 static void wxDoDos2UnixFilename(T
*s
)
928 *s
= wxTolower(*s
); // Case INDEPENDENT
934 void wxDos2UnixFilename(char *s
) { wxDoDos2UnixFilename(s
); }
935 void wxDos2UnixFilename(wchar_t *s
) { wxDoDos2UnixFilename(s
); }
939 #if defined(__WXMSW__) || defined(__OS2__)
940 wxDoUnix2DosFilename(T
*s
)
942 wxDoUnix2DosFilename(T
*WXUNUSED(s
) )
945 // Yes, I really mean this to happen under DOS only! JACS
946 #if defined(__WXMSW__) || defined(__OS2__)
957 void wxUnix2DosFilename(char *s
) { wxDoUnix2DosFilename(s
); }
958 void wxUnix2DosFilename(wchar_t *s
) { wxDoUnix2DosFilename(s
); }
960 #endif // #if WXWIN_COMPATIBILITY_2_8
962 // Concatenate two files to form third
964 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
968 wxFile
in1(file1
), in2(file2
);
969 wxTempFile
out(file3
);
971 if ( !in1
.IsOpened() || !in2
.IsOpened() || !out
.IsOpened() )
975 unsigned char buf
[1024];
977 for( int i
=0; i
<2; i
++)
979 wxFile
*in
= i
==0 ? &in1
: &in2
;
981 if ( (ofs
= in
->Read(buf
,WXSIZEOF(buf
))) == wxInvalidOffset
) return false;
983 if ( !out
.Write(buf
,ofs
) )
985 } while ( ofs
== (ssize_t
)WXSIZEOF(buf
) );
1000 // helper of generic implementation of wxCopyFile()
1001 #if !(defined(__WIN32__) || defined(__OS2__) || defined(__PALMOS__)) && \
1005 wxDoCopyFile(wxFile
& fileIn
,
1006 const wxStructStat
& fbuf
,
1007 const wxString
& filenameDst
,
1010 // reset the umask as we want to create the file with exactly the same
1011 // permissions as the original one
1014 // create file2 with the same permissions than file1 and open it for
1018 if ( !fileOut
.Create(filenameDst
, overwrite
, fbuf
.st_mode
& 0777) )
1021 // copy contents of file1 to file2
1025 ssize_t count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1026 if ( count
== wxInvalidOffset
)
1033 if ( fileOut
.Write(buf
, count
) < (size_t)count
)
1037 // we can expect fileIn to be closed successfully, but we should ensure
1038 // that fileOut was closed as some write errors (disk full) might not be
1039 // detected before doing this
1040 return fileIn
.Close() && fileOut
.Close();
1043 #endif // generic implementation of wxCopyFile
1047 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1049 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1050 // CopyFile() copies file attributes and modification time too, so use it
1051 // instead of our code if available
1053 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1054 if ( !::CopyFile(file1
.t_str(), file2
.t_str(), !overwrite
) )
1056 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1057 file1
.c_str(), file2
.c_str());
1061 #elif defined(__OS2__)
1062 if ( ::DosCopy(file1
.c_str(), file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1064 #elif defined(__PALMOS__)
1065 // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
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 // __WXMSW__ && __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__) && !defined(__WXPALMOS__)
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 || (defined(__MWERKS__) && defined(__MSL__))
1200 int res
= wxRemove(file
);
1201 #elif defined(__WXMAC__)
1202 int res
= unlink(file
.fn_str());
1203 #elif defined(__WXPALMOS__)
1205 // TODO with VFSFileDelete()
1207 int res
= unlink(file
.fn_str());
1211 wxLogSysError(_("File '%s' couldn't be removed"), file
);
1216 bool wxMkdir(const wxString
& dir
, int perm
)
1218 #if defined(__WXPALMOS__)
1221 #if defined(__WXMAC__) && !defined(__UNIX__)
1222 if ( mkdir(dir
.fn_str(), 0) != 0 )
1224 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1225 // for the GNU compiler
1226 #elif (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || \
1227 (defined(__GNUWIN32__) && !defined(__MINGW32__)) || \
1228 defined(__WINE__) || defined(__WXMICROWIN__)
1229 const wxChar
*dirname
= dir
.c_str();
1232 if ( mkdir(wxFNCONV(dirname
)) != 0 )
1234 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1236 #elif defined(__OS2__)
1238 if (::DosCreateDir(dir
.c_str(), NULL
) != 0) // enhance for EAB's??
1239 #elif defined(__DOS__)
1240 const wxChar
*dirname
= dir
.c_str();
1241 #if defined(__WATCOMC__)
1243 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1244 #elif defined(__DJGPP__)
1245 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1247 #error "Unsupported DOS compiler!"
1249 #else // !MSW, !DOS and !OS/2 VAC++
1252 if ( CreateDirectory(dir
.fn_str(), NULL
) == 0 )
1254 if ( wxMkDir(dir
.fn_str()) != 0 )
1258 wxLogSysError(_("Directory '%s' couldn't be created"), dir
);
1263 #endif // PALMOS/!PALMOS
1266 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1268 #if defined(__VMS__)
1269 return false; //to be changed since rmdir exists in VMS7.x
1270 #elif defined(__WXPALMOS__)
1271 // TODO with VFSFileRename()
1274 #if defined(__OS2__)
1275 if ( ::DosDeleteDir(dir
.c_str()) != 0 )
1276 #elif defined(__WXWINCE__)
1277 if ( RemoveDirectory(dir
.fn_str()) == 0 )
1279 if ( wxRmDir(dir
.fn_str()) != 0 )
1282 wxLogSysError(_("Directory '%s' couldn't be deleted"), dir
);
1287 #endif // PALMOS/!PALMOS
1290 // does the path exists? (may have or not '/' or '\\' at the end)
1291 bool wxDirExists(const wxString
& pathName
)
1293 return wxFileName::DirExists(pathName
);
1296 #if WXWIN_COMPATIBILITY_2_8
1298 // Get a temporary filename, opening and closing the file.
1299 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1302 if ( !wxGetTempFileName(prefix
, filename
) )
1307 // work around the PalmOS pacc compiler bug
1308 wxStrcpy(buf
, filename
.data());
1310 wxStrcpy(buf
, filename
);
1313 buf
= MYcopystring(filename
);
1318 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1321 buf
= wxFileName::CreateTempFileName(prefix
);
1323 return !buf
.empty();
1324 #else // !wxUSE_FILE
1325 wxUnusedVar(prefix
);
1329 #endif // wxUSE_FILE/!wxUSE_FILE
1332 #endif // #if WXWIN_COMPATIBILITY_2_8
1334 // Get first file name matching given wild card.
1336 static wxDir
*gs_dir
= NULL
;
1337 static wxString gs_dirPath
;
1339 wxString
wxFindFirstFile(const wxString
& spec
, int flags
)
1341 wxFileName::SplitPath(spec
, &gs_dirPath
, NULL
, NULL
);
1342 if ( gs_dirPath
.empty() )
1343 gs_dirPath
= wxT(".");
1344 if ( !wxEndsWithPathSeparator(gs_dirPath
) )
1345 gs_dirPath
<< wxFILE_SEP_PATH
;
1347 delete gs_dir
; // can be NULL, this is ok
1348 gs_dir
= new wxDir(gs_dirPath
);
1350 if ( !gs_dir
->IsOpened() )
1352 wxLogSysError(_("Cannot enumerate files '%s'"), spec
);
1353 return wxEmptyString
;
1359 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1360 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1361 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1365 gs_dir
->GetFirst(&result
, wxFileNameFromPath(spec
), dirFlags
);
1366 if ( result
.empty() )
1372 return gs_dirPath
+ result
;
1375 wxString
wxFindNextFile()
1377 wxCHECK_MSG( gs_dir
, "", "You must call wxFindFirstFile before!" );
1380 gs_dir
->GetNext(&result
);
1382 if ( result
.empty() )
1388 return gs_dirPath
+ result
;
1392 // Get current working directory.
1393 // If buf is NULL, allocates space using new, else copies into buf.
1394 // wxGetWorkingDirectory() is obsolete, use wxGetCwd()
1395 // wxDoGetCwd() is their common core to be moved
1396 // to wxGetCwd() once wxGetWorkingDirectory() will be removed.
1397 // Do not expose wxDoGetCwd in headers!
1399 wxChar
*wxDoGetCwd(wxChar
*buf
, int sz
)
1401 #if defined(__WXPALMOS__)
1403 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1405 #elif defined(__WXWINCE__)
1407 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1412 buf
= new wxChar
[sz
+ 1];
1415 bool ok
wxDUMMY_INITIALIZE(false);
1417 // for the compilers which have Unicode version of _getcwd(), call it
1418 // directly, for the others call the ANSI version and do the translation
1421 #else // wxUSE_UNICODE
1422 bool needsANSI
= true;
1424 #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
1425 char cbuf
[_MAXPATHLEN
];
1429 #if wxUSE_UNICODE_MSLU
1430 if ( wxGetOsVersion() != wxOS_WINDOWS_9X
)
1432 char *cbuf
= NULL
; // never really used because needsANSI will always be false
1435 ok
= _wgetcwd(buf
, sz
) != NULL
;
1441 #endif // wxUSE_UNICODE
1443 #if defined(_MSC_VER) || defined(__MINGW32__)
1444 ok
= _getcwd(cbuf
, sz
) != NULL
;
1445 #elif defined(__OS2__)
1447 ULONG ulDriveNum
= 0;
1448 ULONG ulDriveMap
= 0;
1449 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
1454 rc
= ::DosQueryCurrentDir( 0 // current drive
1458 cbuf
[0] = char('A' + (ulDriveNum
- 1));
1463 #else // !Win32/VC++ !Mac !OS2
1464 ok
= getcwd(cbuf
, sz
) != NULL
;
1468 // finally convert the result to Unicode if needed
1469 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1470 #endif // wxUSE_UNICODE
1475 wxLogSysError(_("Failed to get the working directory"));
1477 // VZ: the old code used to return "." on error which didn't make any
1478 // sense at all to me - empty string is a better error indicator
1479 // (NULL might be even better but I'm afraid this could lead to
1480 // problems with the old code assuming the return is never NULL)
1483 else // ok, but we might need to massage the path into the right format
1486 // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
1487 // with / deliminers. We don't like that.
1488 for (wxChar
*ch
= buf
; *ch
; ch
++)
1490 if (*ch
== wxT('/'))
1495 // MBN: we hope that in the case the user is compiling a GTK+/Motif app,
1496 // he needs Unix as opposed to Win32 pathnames
1497 #if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
1498 // another example of DOS/Unix mix (Cygwin)
1499 wxString pathUnix
= buf
;
1501 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1502 cygwin_conv_path(CCP_POSIX_TO_WIN_W
, pathUnix
.mb_str(wxConvFile
), buf
, sz
);
1504 char bufA
[_MAXPATHLEN
];
1505 cygwin_conv_to_full_win32_path(pathUnix
.mb_str(wxConvFile
), bufA
);
1506 wxConvFile
.MB2WC(buf
, bufA
, sz
);
1509 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1510 cygwin_conv_path(CCP_POSIX_TO_WIN_A
, pathUnix
, buf
, sz
);
1512 cygwin_conv_to_full_win32_path(pathUnix
, buf
);
1514 #endif // wxUSE_UNICODE
1515 #endif // __CYGWIN__
1528 #if WXWIN_COMPATIBILITY_2_6
1529 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1531 return wxDoGetCwd(buf
,sz
);
1533 #endif // WXWIN_COMPATIBILITY_2_6
1538 wxDoGetCwd(wxStringBuffer(str
, _MAXPATHLEN
), _MAXPATHLEN
);
1542 bool wxSetWorkingDirectory(const wxString
& d
)
1544 bool success
= false;
1545 #if defined(__OS2__)
1548 ::DosSetDefaultDisk(wxToupper(d
[0]) - wxT('A') + 1);
1549 // do not call DosSetCurrentDir when just changing drive,
1550 // since it requires e.g. "d:." instead of "d:"!
1551 if (d
.length() == 2)
1554 success
= (::DosSetCurrentDir(d
.c_str()) == 0);
1555 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1556 success
= (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1557 #elif defined(__WINDOWS__)
1561 // No equivalent in WinCE
1564 success
= (SetCurrentDirectory(d
.fn_str()) != 0);
1567 // Must change drive, too.
1568 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1571 wxChar firstChar
= d
[0];
1575 firstChar
= firstChar
- 32;
1577 // To a drive number
1578 unsigned int driveNo
= firstChar
- 64;
1581 unsigned int noDrives
;
1582 _dos_setdrive(driveNo
, &noDrives
);
1585 success
= (chdir(WXSTRINGCAST d
) == 0);
1591 wxLogSysError(_("Could not set current working directory"));
1596 // Get the OS directory if appropriate (such as the Windows directory).
1597 // On non-Windows platform, probably just return the empty string.
1598 wxString
wxGetOSDirectory()
1601 return wxString(wxT("\\Windows"));
1602 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1604 GetWindowsDirectory(buf
, 256);
1605 return wxString(buf
);
1606 #elif defined(__WXMAC__) && wxOSX_USE_CARBON
1607 return wxMacFindFolderNoSeparator(kOnSystemDisk
, 'macs', false);
1609 return wxEmptyString
;
1613 bool wxEndsWithPathSeparator(const wxString
& filename
)
1615 return !filename
.empty() && wxIsPathSeparator(filename
.Last());
1618 // find a file in a list of directories, returns false if not found
1619 bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
)
1621 // we assume that it's not empty
1622 wxCHECK_MSG( !szFile
.empty(), false,
1623 wxT("empty file name in wxFindFileInPath"));
1625 // skip path separator in the beginning of the file name if present
1627 if ( wxIsPathSeparator(szFile
[0u]) )
1628 szFile2
= szFile
.Mid(1);
1632 wxStringTokenizer
tkn(szPath
, wxPATH_SEP
);
1634 while ( tkn
.HasMoreTokens() )
1636 wxString strFile
= tkn
.GetNextToken();
1637 if ( !wxEndsWithPathSeparator(strFile
) )
1638 strFile
+= wxFILE_SEP_PATH
;
1641 if ( wxFileExists(strFile
) )
1651 #if WXWIN_COMPATIBILITY_2_8
1652 void WXDLLIMPEXP_BASE
wxSplitPath(const wxString
& fileName
,
1657 wxFileName::SplitPath(fileName
, pstrPath
, pstrName
, pstrExt
);
1659 #endif // #if WXWIN_COMPATIBILITY_2_8
1663 time_t WXDLLIMPEXP_BASE
wxFileModificationTime(const wxString
& filename
)
1666 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1669 return mtime
.GetTicks();
1672 #endif // wxUSE_DATETIME
1675 // Parses the filterStr, returning the number of filters.
1676 // Returns 0 if none or if there's a problem.
1677 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1679 int WXDLLIMPEXP_BASE
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1680 wxArrayString
& descriptions
,
1681 wxArrayString
& filters
)
1683 descriptions
.Clear();
1686 wxString
str(filterStr
);
1688 wxString description
, filter
;
1690 while( pos
!= wxNOT_FOUND
)
1692 pos
= str
.Find(wxT('|'));
1693 if ( pos
== wxNOT_FOUND
)
1695 // if there are no '|'s at all in the string just take the entire
1696 // string as filter and make description empty for later autocompletion
1697 if ( filters
.IsEmpty() )
1699 descriptions
.Add(wxEmptyString
);
1700 filters
.Add(filterStr
);
1704 wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
1710 description
= str
.Left(pos
);
1711 str
= str
.Mid(pos
+ 1);
1712 pos
= str
.Find(wxT('|'));
1713 if ( pos
== wxNOT_FOUND
)
1719 filter
= str
.Left(pos
);
1720 str
= str
.Mid(pos
+ 1);
1723 descriptions
.Add(description
);
1724 filters
.Add(filter
);
1727 #if defined(__WXMOTIF__)
1728 // split it so there is one wildcard per entry
1729 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1731 pos
= filters
[i
].Find(wxT(';'));
1732 if (pos
!= wxNOT_FOUND
)
1734 // first split only filters
1735 descriptions
.Insert(descriptions
[i
],i
+1);
1736 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1737 filters
[i
]=filters
[i
].Left(pos
);
1739 // autoreplace new filter in description with pattern:
1740 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1741 // cause split into:
1742 // C/C++ Files(*.cpp)|*.cpp
1743 // C/C++ Files(*.c;*.h)|*.c;*.h
1744 // and next iteration cause another split into:
1745 // C/C++ Files(*.cpp)|*.cpp
1746 // C/C++ Files(*.c)|*.c
1747 // C/C++ Files(*.h)|*.h
1748 for ( size_t k
=i
;k
<i
+2;k
++ )
1750 pos
= descriptions
[k
].Find(filters
[k
]);
1751 if (pos
!= wxNOT_FOUND
)
1753 wxString before
= descriptions
[k
].Left(pos
);
1754 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1755 pos
= before
.Find(wxT('('),true);
1756 if (pos
>before
.Find(wxT(')'),true))
1758 before
= before
.Left(pos
+1);
1759 before
<< filters
[k
];
1760 pos
= after
.Find(wxT(')'));
1761 int pos1
= after
.Find(wxT('('));
1762 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1764 before
<< after
.Mid(pos
);
1765 descriptions
[k
] = before
;
1775 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1777 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1779 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1783 return filters
.GetCount();
1786 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1787 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1789 // quoting the MSDN: "To obtain a handle to a directory, call the
1790 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1791 // doesn't work under Win9x/ME but then it's not needed there anyhow
1792 const DWORD dwAttr
= ::GetFileAttributes(path
.fn_str());
1793 if ( dwAttr
== INVALID_FILE_ATTRIBUTES
)
1795 // file probably doesn't exist at all
1799 if ( wxGetOsVersion() == wxOS_WINDOWS_9X
)
1801 // FAT directories always allow all access, even if they have the
1802 // readonly flag set, and FAT files can only be read-only
1803 return (dwAttr
& FILE_ATTRIBUTE_DIRECTORY
) ||
1804 (access
!= GENERIC_WRITE
||
1805 !(dwAttr
& FILE_ATTRIBUTE_READONLY
));
1808 HANDLE h
= ::CreateFile
1812 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1815 dwAttr
& FILE_ATTRIBUTE_DIRECTORY
1816 ? FILE_FLAG_BACKUP_SEMANTICS
1820 if ( h
!= INVALID_HANDLE_VALUE
)
1823 return h
!= INVALID_HANDLE_VALUE
;
1825 #endif // __WINDOWS__
1827 bool wxIsWritable(const wxString
&path
)
1829 #if defined( __UNIX__ ) || defined(__OS2__)
1830 // access() will take in count also symbolic links
1831 return wxAccess(path
.c_str(), W_OK
) == 0;
1832 #elif defined( __WINDOWS__ )
1833 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1841 bool wxIsReadable(const wxString
&path
)
1843 #if defined( __UNIX__ ) || defined(__OS2__)
1844 // access() will take in count also symbolic links
1845 return wxAccess(path
.c_str(), R_OK
) == 0;
1846 #elif defined( __WINDOWS__ )
1847 return wxCheckWin32Permission(path
, GENERIC_READ
);
1855 bool wxIsExecutable(const wxString
&path
)
1857 #if defined( __UNIX__ ) || defined(__OS2__)
1858 // access() will take in count also symbolic links
1859 return wxAccess(path
.c_str(), X_OK
) == 0;
1860 #elif defined( __WINDOWS__ )
1861 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1869 // Return the type of an open file
1871 // Some file types on some platforms seem seekable but in fact are not.
1872 // The main use of this function is to allow such cases to be detected
1873 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1875 // This is important for the archive streams, which benefit greatly from
1876 // being able to seek on a stream, but which will produce corrupt archives
1877 // if they unknowingly seek on a non-seekable stream.
1879 // wxFILE_KIND_DISK is a good catch all return value, since other values
1880 // disable features of the archive streams. Some other value must be returned
1881 // for a file type that appears seekable but isn't.
1884 // * Pipes on Windows
1885 // * Files on VMS with a record format other than StreamLF
1887 wxFileKind
wxGetFileKind(int fd
)
1889 #if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1890 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1892 case FILE_TYPE_CHAR
:
1893 return wxFILE_KIND_TERMINAL
;
1894 case FILE_TYPE_DISK
:
1895 return wxFILE_KIND_DISK
;
1896 case FILE_TYPE_PIPE
:
1897 return wxFILE_KIND_PIPE
;
1900 return wxFILE_KIND_UNKNOWN
;
1902 #elif defined(__UNIX__)
1904 return wxFILE_KIND_TERMINAL
;
1909 if (S_ISFIFO(st
.st_mode
))
1910 return wxFILE_KIND_PIPE
;
1911 if (!S_ISREG(st
.st_mode
))
1912 return wxFILE_KIND_UNKNOWN
;
1914 #if defined(__VMS__)
1915 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1916 return wxFILE_KIND_UNKNOWN
;
1919 return wxFILE_KIND_DISK
;
1922 #define wxFILEKIND_STUB
1924 return wxFILE_KIND_DISK
;
1928 wxFileKind
wxGetFileKind(FILE *fp
)
1930 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1931 // Should be fixed in version 1.4.
1932 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1934 return wxFILE_KIND_DISK
;
1935 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WINE__)
1936 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1938 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1943 //------------------------------------------------------------------------
1944 // wild character routines
1945 //------------------------------------------------------------------------
1947 bool wxIsWild( const wxString
& pattern
)
1949 for ( wxString::const_iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
)
1951 switch ( (*p
).GetValue() )
1960 if ( ++p
== pattern
.end() )
1968 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1970 * The match procedure is public domain code (from ircII's reg.c)
1971 * but modified to suit our tastes (RN: No "%" syntax I guess)
1974 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1978 /* Match if both are empty. */
1982 const wxChar
*m
= pat
.c_str(),
1990 if (dot_special
&& (*n
== wxT('.')))
1992 /* Never match so that hidden Unix files
1993 * are never found. */
2006 else if (*m
== wxT('?'))
2014 if (*m
== wxT('\\'))
2017 /* Quoting "nothing" is a bad thing */
2024 * If we are out of both strings or we just
2025 * saw a wildcard, then we can say we have a
2036 * We could check for *n == NULL at this point, but
2037 * since it's more common to have a character there,
2038 * check to see if they match first (m and n) and
2039 * then if they don't match, THEN we can check for
2055 * If there are no more characters in the
2056 * string, but we still need to find another
2057 * character (*m != NULL), then it will be
2058 * impossible to match it
2077 #pragma warning(default:4706) // assignment within conditional expression