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 #ifndef INVALID_FILE_ATTRIBUTES
102 #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 #if WXWIN_COMPATIBILITY_2_8
110 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
113 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
115 // VisualAge C++ V4.0 cannot have any external linkage const decs
116 // in headers included by more than one primary source
118 const int wxInvalidOffset
= -1;
121 // ============================================================================
123 // ============================================================================
125 // ----------------------------------------------------------------------------
126 // wrappers around standard POSIX functions
127 // ----------------------------------------------------------------------------
129 #if wxUSE_UNICODE && defined __BORLANDC__ \
130 && __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
132 // BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
133 // regardless of the mode parameter. This hack works around the problem by
134 // setting the mode with _wchmod.
136 int wxCRT_OpenW(const wchar_t *pathname
, int flags
, mode_t mode
)
140 // we only want to fix the mode when the file is actually created, so
141 // when creating first try doing it O_EXCL so we can tell if the file
142 // was already there.
143 if ((flags
& O_CREAT
) && !(flags
& O_EXCL
) && (mode
& wxS_IWUSR
) != 0)
146 int fd
= _wopen(pathname
, flags
| moreflags
, mode
);
148 // the file was actually created and needs fixing
149 if (fd
!= -1 && (flags
& O_CREAT
) != 0 && (mode
& wxS_IWUSR
) != 0)
152 _wchmod(pathname
, mode
);
153 fd
= _wopen(pathname
, flags
& ~(O_EXCL
| O_CREAT
));
155 // the open failed, but it may have been because the added O_EXCL stopped
156 // the opening of an existing file, so try again without.
157 else if (fd
== -1 && moreflags
!= 0)
159 fd
= _wopen(pathname
, flags
& ~O_CREAT
);
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 bool wxPathList::Add(const wxString
& path
)
173 // add a path separator to force wxFileName to interpret it always as a directory
174 // (i.e. if we are called with '/home/user' we want to consider it a folder and
175 // not, as wxFileName would consider, a filename).
176 wxFileName
fn(path
+ wxFileName::GetPathSeparator());
178 // add only normalized relative/absolute paths
179 // NB: we won't do wxPATH_NORM_DOTS in order to avoid problems when trying to
180 // normalize paths which starts with ".." (which can be normalized only if
181 // we use also wxPATH_NORM_ABSOLUTE - which we don't want to use).
182 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
185 wxString toadd
= fn
.GetPath();
186 if (Index(toadd
) == wxNOT_FOUND
)
187 wxArrayString::Add(toadd
); // do not add duplicates
192 void wxPathList::Add(const wxArrayString
&arr
)
194 for (size_t j
=0; j
< arr
.GetCount(); j
++)
198 // Add paths e.g. from the PATH environment variable
199 void wxPathList::AddEnvList (const wxString
& WXUNUSED_IN_WINCE(envVariable
))
201 // No environment variables on WinCE
204 // The space has been removed from the tokenizers, otherwise a
205 // path such as "C:\Program Files" would be split into 2 paths:
206 // "C:\Program" and "Files"; this is true for both Windows and Unix.
208 static const wxChar PATH_TOKS
[] =
209 #if defined(__WINDOWS__) || defined(__OS2__)
210 wxT(";"); // Don't separate with colon in DOS (used for drive)
216 if ( wxGetEnv(envVariable
, &val
) )
218 // split into an array of string the value of the env var
219 wxArrayString arr
= wxStringTokenize(val
, PATH_TOKS
);
220 WX_APPEND_ARRAY(*this, arr
);
222 #endif // !__WXWINCE__
225 // Given a full filename (with path), ensure that that file can
226 // be accessed again USING FILENAME ONLY by adding the path
227 // to the list if not already there.
228 bool wxPathList::EnsureFileAccessible (const wxString
& path
)
230 return Add(wxPathOnly(path
));
233 #if WXWIN_COMPATIBILITY_2_6
234 bool wxPathList::Member (const wxString
& path
) const
236 return Index(path
) != wxNOT_FOUND
;
240 wxString
wxPathList::FindValidPath (const wxString
& file
) const
242 // normalize the given string as it could be a path + a filename
243 // and not only a filename
247 // NB: normalize without making absolute otherwise calling this function with
248 // e.g. "b/c.txt" would result in removing the directory 'b' and the for loop
249 // below would only add to the paths of this list the 'c.txt' part when doing
250 // the existence checks...
251 // NB: we don't use wxPATH_NORM_DOTS here, too (see wxPathList::Add for more info)
252 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
253 return wxEmptyString
;
255 wxASSERT_MSG(!fn
.IsDir(), wxT("Cannot search for directories; only for files"));
257 strend
= fn
.GetFullName(); // search for the file name and ignore the path part
259 strend
= fn
.GetFullPath();
261 for (size_t i
=0; i
<GetCount(); i
++)
263 wxString strstart
= Item(i
);
264 if (!strstart
.IsEmpty() && strstart
.Last() != wxFileName::GetPathSeparator())
265 strstart
+= wxFileName::GetPathSeparator();
267 if (wxFileExists(strstart
+ strend
))
268 return strstart
+ strend
; // Found!
271 return wxEmptyString
; // Not found
274 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
) const
276 wxString f
= FindValidPath(file
);
277 if ( f
.empty() || wxIsAbsolutePath(f
) )
280 wxString buf
= ::wxGetCwd();
282 if ( !wxEndsWithPathSeparator(buf
) )
284 buf
+= wxFILE_SEP_PATH
;
291 // ----------------------------------------------------------------------------
292 // miscellaneous global functions
293 // ----------------------------------------------------------------------------
295 #if WXWIN_COMPATIBILITY_2_8
296 static inline wxChar
* MYcopystring(const wxString
& s
)
298 wxChar
* copy
= new wxChar
[s
.length() + 1];
299 return wxStrcpy(copy
, s
.c_str());
302 template<typename CharType
>
303 static inline CharType
* MYcopystring(const CharType
* s
)
305 CharType
* copy
= new CharType
[wxStrlen(s
) + 1];
306 return wxStrcpy(copy
, s
);
312 wxFileExists (const wxString
& filename
)
314 return wxFileName::FileExists(filename
);
318 wxIsAbsolutePath (const wxString
& filename
)
320 if (!filename
.empty())
322 // Unix like or Windows
323 if (filename
[0] == wxT('/'))
326 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
329 #if defined(__WINDOWS__) || defined(__OS2__)
331 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
338 #if WXWIN_COMPATIBILITY_2_8
340 * Strip off any extension (dot something) from end of file,
341 * IF one exists. Inserts zero into buffer.
346 static void wxDoStripExtension(T
*buffer
)
348 int len
= wxStrlen(buffer
);
352 if (buffer
[i
] == wxT('.'))
361 void wxStripExtension(char *buffer
) { wxDoStripExtension(buffer
); }
362 void wxStripExtension(wchar_t *buffer
) { wxDoStripExtension(buffer
); }
364 void wxStripExtension(wxString
& buffer
)
366 buffer
= wxFileName::StripExtension(buffer
);
369 // Destructive removal of /./ and /../ stuff
370 template<typename CharType
>
371 static CharType
*wxDoRealPath (CharType
*path
)
373 static const CharType SEP
= wxFILE_SEP_PATH
;
375 wxUnix2DosFilename(path
);
377 if (path
[0] && path
[1]) {
378 /* MATTHEW: special case "/./x" */
380 if (path
[2] == SEP
&& path
[1] == wxT('.'))
388 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
391 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--)
396 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
397 && (q
- 1 <= path
|| q
[-1] != SEP
))
400 if (path
[0] == wxT('\0'))
405 #if defined(__WXMSW__) || defined(__OS2__)
406 /* Check that path[2] is NULL! */
407 else if (path
[1] == wxT(':') && !path
[2])
416 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
424 char *wxRealPath(char *path
)
426 return wxDoRealPath(path
);
429 wchar_t *wxRealPath(wchar_t *path
)
431 return wxDoRealPath(path
);
434 wxString
wxRealPath(const wxString
& path
)
436 wxChar
*buf1
=MYcopystring(path
);
437 wxChar
*buf2
=wxRealPath(buf1
);
445 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
447 if (filename
.empty())
450 if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
)))
452 wxString buf
= ::wxGetCwd();
453 wxChar ch
= buf
.Last();
455 if (ch
!= wxT('\\') && ch
!= wxT('/'))
461 buf
<< wxFileFunctionsBuffer
;
462 buf
= wxRealPath( buf
);
463 return MYcopystring( buf
);
465 return MYcopystring( wxFileFunctionsBuffer
);
471 ~user/ => user's home dir
472 If the environment variable a = "foo" and b = "bar" then:
489 /* input name in name, pathname output to buf. */
491 template<typename CharType
>
492 static CharType
*wxDoExpandPath(CharType
*buf
, const wxString
& name
)
494 register CharType
*d
, *s
, *nm
;
495 CharType lnm
[_MAXPATHLEN
];
498 // Some compilers don't like this line.
499 // const CharType trimchars[] = wxT("\n \t");
501 CharType trimchars
[4];
502 trimchars
[0] = wxT('\n');
503 trimchars
[1] = wxT(' ');
504 trimchars
[2] = wxT('\t');
507 static const CharType SEP
= wxFILE_SEP_PATH
;
509 //wxUnix2DosFilename(path);
515 nm
= ::MYcopystring(static_cast<const CharType
*>(name
.c_str())); // Make a scratch copy
516 CharType
*nm_tmp
= nm
;
518 /* Skip leading whitespace and cr */
519 while (wxStrchr(trimchars
, *nm
) != NULL
)
521 /* And strip off trailing whitespace and cr */
522 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
523 while (q
-- && wxStrchr(trimchars
, *s
) != NULL
)
531 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
534 /* Expand inline environment variables */
552 while ((*d
++ = *s
) != 0) {
554 if (*s
== wxT('\\')) {
555 if ((*(d
- 1) = *++s
)!=0) {
563 // No env variables on WinCE
566 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
568 if (*s
++ == wxT('$'))
571 register CharType
*start
= d
;
572 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
573 register CharType
*value
;
574 while ((*d
++ = *s
) != 0)
575 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
580 value
= wxGetenv(braces
? start
+ 1 : start
);
582 for ((d
= start
- 1); (*d
++ = *value
++) != 0;)
596 /* Expand ~ and ~user */
599 if (nm
[0] == wxT('~') && !q
)
602 if (nm
[1] == SEP
|| nm
[1] == 0)
604 homepath
= wxGetUserHome(wxEmptyString
);
605 if (!homepath
.empty()) {
606 s
= (CharType
*)(const CharType
*)homepath
.c_str();
611 { /* ~user/filename */
612 register CharType
*nnm
;
613 for (s
= nm
; *s
&& *s
!= SEP
; s
++)
617 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
618 was_sep
= (*s
== SEP
);
619 nnm
= *s
? s
+ 1 : s
;
621 homepath
= wxGetUserHome(wxString(nm
+ 1));
622 if (homepath
.empty())
624 if (was_sep
) /* replace only if it was there: */
631 s
= (CharType
*)(const CharType
*)homepath
.c_str();
637 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
639 while (wxT('\0') != (*d
++ = *s
++))
642 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
646 while ((*d
++ = *s
++) != 0)
650 delete[] nm_tmp
; // clean up alloc
651 /* Now clean up the buffer */
652 return wxRealPath(buf
);
655 char *wxExpandPath(char *buf
, const wxString
& name
)
657 return wxDoExpandPath(buf
, name
);
660 wchar_t *wxExpandPath(wchar_t *buf
, const wxString
& name
)
662 return wxDoExpandPath(buf
, name
);
666 /* Contract Paths to be build upon an environment variable
669 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
671 The call wxExpandPath can convert these back!
674 wxContractPath (const wxString
& filename
,
675 const wxString
& WXUNUSED_IN_WINCE(envname
),
676 const wxString
& user
)
678 static wxChar dest
[_MAXPATHLEN
];
680 if (filename
.empty())
683 wxStrcpy (dest
, filename
);
685 wxUnix2DosFilename(dest
);
688 // Handle environment
692 if (!envname
.empty() && !(val
= wxGetenv (envname
)).empty() &&
693 (tcp
= wxStrstr (dest
, val
)) != NULL
)
695 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ val
.length());
698 wxStrcpy (tcp
, envname
);
699 wxStrcat (tcp
, wxT("}"));
700 wxStrcat (tcp
, wxFileFunctionsBuffer
);
704 // Handle User's home (ignore root homes!)
705 val
= wxGetUserHome (user
);
709 const size_t len
= val
.length();
713 if (wxStrncmp(dest
, val
, len
) == 0)
715 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
717 wxStrcat(wxFileFunctionsBuffer
, user
);
718 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
719 wxStrcpy (dest
, wxFileFunctionsBuffer
);
725 #endif // #if WXWIN_COMPATIBILITY_2_8
727 // Return just the filename, not the path (basename)
728 wxChar
*wxFileNameFromPath (wxChar
*path
)
731 wxString n
= wxFileNameFromPath(p
);
733 return path
+ p
.length() - n
.length();
736 wxString
wxFileNameFromPath (const wxString
& path
)
739 wxFileName::SplitPath(path
, NULL
, &name
, &ext
);
741 wxString fullname
= name
;
744 fullname
<< wxFILE_SEP_EXT
<< ext
;
750 // Return just the directory, or NULL if no directory
752 wxPathOnly (wxChar
*path
)
756 static wxChar buf
[_MAXPATHLEN
];
759 wxStrcpy (buf
, path
);
761 int l
= wxStrlen(path
);
764 // Search backward for a backward or forward slash
767 // Unix like or Windows
768 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
774 if (path
[i
] == wxT(']'))
783 #if defined(__WXMSW__) || defined(__OS2__)
784 // Try Drive specifier
785 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
787 // A:junk --> A:. (since A:.\junk Not A:\junk)
797 // Return just the directory, or NULL if no directory
798 wxString
wxPathOnly (const wxString
& path
)
802 wxChar buf
[_MAXPATHLEN
];
807 int l
= path
.length();
810 // Search backward for a backward or forward slash
813 // Unix like or Windows
814 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
816 // Don't return an empty string
820 return wxString(buf
);
823 if (path
[i
] == wxT(']'))
826 return wxString(buf
);
832 #if defined(__WXMSW__) || defined(__OS2__)
833 // Try Drive specifier
834 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
836 // A:junk --> A:. (since A:.\junk Not A:\junk)
839 return wxString(buf
);
843 return wxEmptyString
;
846 // Utility for converting delimiters in DOS filenames to UNIX style
847 // and back again - or we get nasty problems with delimiters.
848 // Also, convert to lower case, since case is significant in UNIX.
850 #if defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)
852 #define kDefaultPathStyle kCFURLPOSIXPathStyle
854 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
857 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
858 if ( additionalPathComponent
)
860 CFURLRef parentURLRef
= fullURLRef
;
861 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
862 additionalPathComponent
,false);
863 CFRelease( parentURLRef
) ;
865 CFStringRef cfString
= CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
);
866 CFRelease( fullURLRef
) ;
867 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfString
);
868 CFRelease( cfString
);
869 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
870 return wxCFStringRef(cfMutableString
).AsString();
873 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
875 OSStatus err
= noErr
;
876 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(path
));
877 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
878 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
879 CFRelease( cfMutableString
);
882 if ( CFURLGetFSRef(url
, fsRef
) == false )
893 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
895 CFStringRef cfname
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
898 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfname
);
900 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
901 return wxCFStringRef(cfMutableString
).AsString() ;
906 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
909 if ( FSpMakeFSRef( spec
, &fsRef
) == noErr
)
911 return wxMacFSRefToPath( &fsRef
) ;
913 return wxEmptyString
;
916 void wxMacFilename2FSSpec( const wxString
& path
, FSSpec
*spec
)
918 OSStatus err
= noErr
;
920 wxMacPathToFSRef( path
, &fsRef
);
921 err
= FSGetCatalogInfo(&fsRef
, kFSCatInfoNone
, NULL
, NULL
, spec
, NULL
);
929 #if WXWIN_COMPATIBILITY_2_8
932 static void wxDoDos2UnixFilename(T
*s
)
941 *s
= wxTolower(*s
); // Case INDEPENDENT
947 void wxDos2UnixFilename(char *s
) { wxDoDos2UnixFilename(s
); }
948 void wxDos2UnixFilename(wchar_t *s
) { wxDoDos2UnixFilename(s
); }
952 #if defined(__WXMSW__) || defined(__OS2__)
953 wxDoUnix2DosFilename(T
*s
)
955 wxDoUnix2DosFilename(T
*WXUNUSED(s
) )
958 // Yes, I really mean this to happen under DOS only! JACS
959 #if defined(__WXMSW__) || defined(__OS2__)
970 void wxUnix2DosFilename(char *s
) { wxDoUnix2DosFilename(s
); }
971 void wxUnix2DosFilename(wchar_t *s
) { wxDoUnix2DosFilename(s
); }
973 #endif // #if WXWIN_COMPATIBILITY_2_8
975 // Concatenate two files to form third
977 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
981 wxFile
in1(file1
), in2(file2
);
982 wxTempFile
out(file3
);
984 if ( !in1
.IsOpened() || !in2
.IsOpened() || !out
.IsOpened() )
988 unsigned char buf
[1024];
990 for( int i
=0; i
<2; i
++)
992 wxFile
*in
= i
==0 ? &in1
: &in2
;
994 if ( (ofs
= in
->Read(buf
,WXSIZEOF(buf
))) == wxInvalidOffset
) return false;
996 if ( !out
.Write(buf
,ofs
) )
998 } while ( ofs
== (ssize_t
)WXSIZEOF(buf
) );
1001 return out
.Commit();
1013 // helper of generic implementation of wxCopyFile()
1014 #if !(defined(__WIN32__) || defined(__OS2__) || defined(__PALMOS__)) && \
1018 wxDoCopyFile(wxFile
& fileIn
,
1019 const wxStructStat
& fbuf
,
1020 const wxString
& filenameDst
,
1023 // reset the umask as we want to create the file with exactly the same
1024 // permissions as the original one
1027 // create file2 with the same permissions than file1 and open it for
1031 if ( !fileOut
.Create(filenameDst
, overwrite
, fbuf
.st_mode
& 0777) )
1034 // copy contents of file1 to file2
1038 ssize_t count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1039 if ( count
== wxInvalidOffset
)
1046 if ( fileOut
.Write(buf
, count
) < (size_t)count
)
1050 // we can expect fileIn to be closed successfully, but we should ensure
1051 // that fileOut was closed as some write errors (disk full) might not be
1052 // detected before doing this
1053 return fileIn
.Close() && fileOut
.Close();
1056 #endif // generic implementation of wxCopyFile
1060 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1062 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1063 // CopyFile() copies file attributes and modification time too, so use it
1064 // instead of our code if available
1066 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1067 if ( !::CopyFile(file1
.t_str(), file2
.t_str(), !overwrite
) )
1069 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1070 file1
.c_str(), file2
.c_str());
1074 #elif defined(__OS2__)
1075 if ( ::DosCopy(file1
.c_str(), file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1077 #elif defined(__PALMOS__)
1078 // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
1080 #elif wxUSE_FILE // !Win32
1083 // get permissions of file1
1084 if ( wxStat( file1
, &fbuf
) != 0 )
1086 // the file probably doesn't exist or we haven't the rights to read
1088 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1093 // open file1 for reading
1094 wxFile
fileIn(file1
, wxFile::read
);
1095 if ( !fileIn
.IsOpened() )
1098 // remove file2, if it exists. This is needed for creating
1099 // file2 with the correct permissions in the next step
1100 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1102 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1107 wxDoCopyFile(fileIn
, fbuf
, file2
, overwrite
);
1109 #if defined(__WXMAC__) || defined(__WXCOCOA__)
1110 // copy the resource fork of the file too if it's present
1111 wxString pathRsrcOut
;
1115 // suppress error messages from this block as resource forks don't have
1119 // it's not enough to check for file existence: it always does on HFS
1120 // but is empty for files without resources
1121 if ( fileRsrcIn
.Open(file1
+ wxT("/..namedfork/rsrc")) &&
1122 fileRsrcIn
.Length() > 0 )
1124 // we must be using HFS or another filesystem with resource fork
1125 // support, suppose that destination file system also is HFS[-like]
1126 pathRsrcOut
= file2
+ wxT("/..namedfork/rsrc");
1128 else // check if we have resource fork in separate file (non-HFS case)
1130 wxFileName
fnRsrc(file1
);
1131 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1134 if ( fileRsrcIn
.Open( fnRsrc
.GetFullPath() ) )
1137 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1139 pathRsrcOut
= fnRsrc
.GetFullPath();
1144 if ( !pathRsrcOut
.empty() )
1146 if ( !wxDoCopyFile(fileRsrcIn
, fbuf
, pathRsrcOut
, overwrite
) )
1149 #endif // wxMac || wxCocoa
1151 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1152 // no chmod in VA. Should be some permission API for HPFS386 partitions
1154 if ( chmod(file2
.fn_str(), fbuf
.st_mode
) != 0 )
1156 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1160 #endif // OS/2 || Mac
1162 #else // !Win32 && ! wxUSE_FILE
1164 // impossible to simulate with wxWidgets API
1167 wxUnusedVar(overwrite
);
1170 #endif // __WXMSW__ && __WIN32__
1176 wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1178 if ( !overwrite
&& wxFileExists(file2
) )
1182 _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
1183 file1
.c_str(), file2
.c_str()
1189 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
1190 // Normal system call
1191 if ( wxRename (file1
, file2
) == 0 )
1196 if (wxCopyFile(file1
, file2
, overwrite
)) {
1197 wxRemoveFile(file1
);
1204 bool wxRemoveFile(const wxString
& file
)
1206 #if defined(__VISUALC__) \
1207 || defined(__BORLANDC__) \
1208 || defined(__WATCOMC__) \
1209 || defined(__DMC__) \
1210 || defined(__GNUWIN32__) \
1211 || (defined(__MWERKS__) && defined(__MSL__))
1212 int res
= wxRemove(file
);
1213 #elif defined(__WXMAC__)
1214 int res
= unlink(file
.fn_str());
1215 #elif defined(__WXPALMOS__)
1217 // TODO with VFSFileDelete()
1219 int res
= unlink(file
.fn_str());
1225 bool wxMkdir(const wxString
& dir
, int perm
)
1227 #if defined(__WXPALMOS__)
1230 #if defined(__WXMAC__) && !defined(__UNIX__)
1231 if ( mkdir(dir
.fn_str(), 0) != 0 )
1233 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1234 // for the GNU compiler
1235 #elif (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || \
1236 (defined(__GNUWIN32__) && !defined(__MINGW32__)) || \
1237 defined(__WINE__) || defined(__WXMICROWIN__)
1238 const wxChar
*dirname
= dir
.c_str();
1241 if ( mkdir(wxFNCONV(dirname
)) != 0 )
1243 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1245 #elif defined(__OS2__)
1247 if (::DosCreateDir(dir
.c_str(), NULL
) != 0) // enhance for EAB's??
1248 #elif defined(__DOS__)
1249 const wxChar
*dirname
= dir
.c_str();
1250 #if defined(__WATCOMC__)
1252 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1253 #elif defined(__DJGPP__)
1254 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1256 #error "Unsupported DOS compiler!"
1258 #else // !MSW, !DOS and !OS/2 VAC++
1261 if ( CreateDirectory(dir
.fn_str(), NULL
) == 0 )
1263 if ( wxMkDir(dir
.fn_str()) != 0 )
1267 wxLogSysError(_("Directory '%s' couldn't be created"), dir
);
1272 #endif // PALMOS/!PALMOS
1275 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1277 #if defined(__VMS__)
1278 return false; //to be changed since rmdir exists in VMS7.x
1279 #elif defined(__WXPALMOS__)
1280 // TODO with VFSFileRename()
1283 #if defined(__OS2__)
1284 if ( ::DosDeleteDir(dir
.c_str()) != 0 )
1285 #elif defined(__WXWINCE__)
1286 if ( RemoveDirectory(dir
.fn_str()) == 0 )
1288 if ( wxRmDir(dir
.fn_str()) != 0 )
1291 wxLogSysError(_("Directory '%s' couldn't be deleted"), dir
);
1296 #endif // PALMOS/!PALMOS
1299 // does the path exists? (may have or not '/' or '\\' at the end)
1300 bool wxDirExists(const wxString
& pathName
)
1302 return wxFileName::DirExists(pathName
);
1305 #if WXWIN_COMPATIBILITY_2_8
1307 // Get a temporary filename, opening and closing the file.
1308 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1311 if ( !wxGetTempFileName(prefix
, filename
) )
1316 // work around the PalmOS pacc compiler bug
1317 wxStrcpy(buf
, filename
.data());
1319 wxStrcpy(buf
, filename
);
1322 buf
= MYcopystring(filename
);
1327 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1330 buf
= wxFileName::CreateTempFileName(prefix
);
1332 return !buf
.empty();
1333 #else // !wxUSE_FILE
1334 wxUnusedVar(prefix
);
1338 #endif // wxUSE_FILE/!wxUSE_FILE
1341 #endif // #if WXWIN_COMPATIBILITY_2_8
1343 // Get first file name matching given wild card.
1345 static wxDir
*gs_dir
= NULL
;
1346 static wxString gs_dirPath
;
1348 wxString
wxFindFirstFile(const wxString
& spec
, int flags
)
1350 wxFileName::SplitPath(spec
, &gs_dirPath
, NULL
, NULL
);
1351 if ( gs_dirPath
.empty() )
1352 gs_dirPath
= wxT(".");
1353 if ( !wxEndsWithPathSeparator(gs_dirPath
) )
1354 gs_dirPath
<< wxFILE_SEP_PATH
;
1356 delete gs_dir
; // can be NULL, this is ok
1357 gs_dir
= new wxDir(gs_dirPath
);
1359 if ( !gs_dir
->IsOpened() )
1361 wxLogSysError(_("Can not enumerate files '%s'"), spec
);
1362 return wxEmptyString
;
1368 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1369 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1370 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1374 gs_dir
->GetFirst(&result
, wxFileNameFromPath(spec
), dirFlags
);
1375 if ( result
.empty() )
1381 return gs_dirPath
+ result
;
1384 wxString
wxFindNextFile()
1386 wxCHECK_MSG( gs_dir
, "", "You must call wxFindFirstFile before!" );
1389 gs_dir
->GetNext(&result
);
1391 if ( result
.empty() )
1397 return gs_dirPath
+ result
;
1401 // Get current working directory.
1402 // If buf is NULL, allocates space using new, else copies into buf.
1403 // wxGetWorkingDirectory() is obsolete, use wxGetCwd()
1404 // wxDoGetCwd() is their common core to be moved
1405 // to wxGetCwd() once wxGetWorkingDirectory() will be removed.
1406 // Do not expose wxDoGetCwd in headers!
1408 wxChar
*wxDoGetCwd(wxChar
*buf
, int sz
)
1410 #if defined(__WXPALMOS__)
1412 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1414 #elif defined(__WXWINCE__)
1416 if(buf
&& sz
>0) buf
[0] = wxT('\0');
1421 buf
= new wxChar
[sz
+ 1];
1424 bool ok
wxDUMMY_INITIALIZE(false);
1426 // for the compilers which have Unicode version of _getcwd(), call it
1427 // directly, for the others call the ANSI version and do the translation
1430 #else // wxUSE_UNICODE
1431 bool needsANSI
= true;
1433 #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
1434 char cbuf
[_MAXPATHLEN
];
1438 #if wxUSE_UNICODE_MSLU
1439 if ( wxGetOsVersion() != wxOS_WINDOWS_9X
)
1441 char *cbuf
= NULL
; // never really used because needsANSI will always be false
1444 ok
= _wgetcwd(buf
, sz
) != NULL
;
1450 #endif // wxUSE_UNICODE
1452 #if defined(_MSC_VER) || defined(__MINGW32__)
1453 ok
= _getcwd(cbuf
, sz
) != NULL
;
1454 #elif defined(__OS2__)
1456 ULONG ulDriveNum
= 0;
1457 ULONG ulDriveMap
= 0;
1458 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
1463 rc
= ::DosQueryCurrentDir( 0 // current drive
1467 cbuf
[0] = char('A' + (ulDriveNum
- 1));
1472 #else // !Win32/VC++ !Mac !OS2
1473 ok
= getcwd(cbuf
, sz
) != NULL
;
1477 // finally convert the result to Unicode if needed
1478 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1479 #endif // wxUSE_UNICODE
1484 wxLogSysError(_("Failed to get the working directory"));
1486 // VZ: the old code used to return "." on error which didn't make any
1487 // sense at all to me - empty string is a better error indicator
1488 // (NULL might be even better but I'm afraid this could lead to
1489 // problems with the old code assuming the return is never NULL)
1492 else // ok, but we might need to massage the path into the right format
1495 // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
1496 // with / deliminers. We don't like that.
1497 for (wxChar
*ch
= buf
; *ch
; ch
++)
1499 if (*ch
== wxT('/'))
1504 // MBN: we hope that in the case the user is compiling a GTK+/Motif app,
1505 // he needs Unix as opposed to Win32 pathnames
1506 #if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
1507 // another example of DOS/Unix mix (Cygwin)
1508 wxString pathUnix
= buf
;
1510 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1511 cygwin_conv_path(CCP_POSIX_TO_WIN_W
, pathUnix
.mb_str(wxConvFile
), buf
, sz
);
1513 char bufA
[_MAXPATHLEN
];
1514 cygwin_conv_to_full_win32_path(pathUnix
.mb_str(wxConvFile
), bufA
);
1515 wxConvFile
.MB2WC(buf
, bufA
, sz
);
1518 #if CYGWIN_VERSION_DLL_MAJOR >= 1007
1519 cygwin_conv_path(CCP_POSIX_TO_WIN_A
, pathUnix
, buf
, sz
);
1521 cygwin_conv_to_full_win32_path(pathUnix
, buf
);
1523 #endif // wxUSE_UNICODE
1524 #endif // __CYGWIN__
1537 #if WXWIN_COMPATIBILITY_2_6
1538 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1540 return wxDoGetCwd(buf
,sz
);
1542 #endif // WXWIN_COMPATIBILITY_2_6
1547 wxDoGetCwd(wxStringBuffer(str
, _MAXPATHLEN
), _MAXPATHLEN
);
1551 bool wxSetWorkingDirectory(const wxString
& d
)
1553 #if defined(__OS2__)
1556 ::DosSetDefaultDisk(wxToupper(d
[0]) - wxT('A') + 1);
1557 // do not call DosSetCurrentDir when just changing drive,
1558 // since it requires e.g. "d:." instead of "d:"!
1559 if (d
.length() == 2)
1562 return (::DosSetCurrentDir(d
.c_str()) == 0);
1563 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1564 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1565 #elif defined(__WINDOWS__)
1569 // No equivalent in WinCE
1573 return (bool)(SetCurrentDirectory(d
.fn_str()) != 0);
1576 // Must change drive, too.
1577 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1580 wxChar firstChar
= d
[0];
1584 firstChar
= firstChar
- 32;
1586 // To a drive number
1587 unsigned int driveNo
= firstChar
- 64;
1590 unsigned int noDrives
;
1591 _dos_setdrive(driveNo
, &noDrives
);
1594 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1602 // Get the OS directory if appropriate (such as the Windows directory).
1603 // On non-Windows platform, probably just return the empty string.
1604 wxString
wxGetOSDirectory()
1607 return wxString(wxT("\\Windows"));
1608 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1610 GetWindowsDirectory(buf
, 256);
1611 return wxString(buf
);
1612 #elif defined(__WXMAC__) && wxOSX_USE_CARBON
1613 return wxMacFindFolderNoSeparator(kOnSystemDisk
, 'macs', false);
1615 return wxEmptyString
;
1619 bool wxEndsWithPathSeparator(const wxString
& filename
)
1621 return !filename
.empty() && wxIsPathSeparator(filename
.Last());
1624 // find a file in a list of directories, returns false if not found
1625 bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
)
1627 // we assume that it's not empty
1628 wxCHECK_MSG( !szFile
.empty(), false,
1629 wxT("empty file name in wxFindFileInPath"));
1631 // skip path separator in the beginning of the file name if present
1633 if ( wxIsPathSeparator(szFile
[0u]) )
1634 szFile2
= szFile
.Mid(1);
1638 wxStringTokenizer
tkn(szPath
, wxPATH_SEP
);
1640 while ( tkn
.HasMoreTokens() )
1642 wxString strFile
= tkn
.GetNextToken();
1643 if ( !wxEndsWithPathSeparator(strFile
) )
1644 strFile
+= wxFILE_SEP_PATH
;
1647 if ( wxFileExists(strFile
) )
1657 #if WXWIN_COMPATIBILITY_2_8
1658 void WXDLLIMPEXP_BASE
wxSplitPath(const wxString
& fileName
,
1663 wxFileName::SplitPath(fileName
, pstrPath
, pstrName
, pstrExt
);
1665 #endif // #if WXWIN_COMPATIBILITY_2_8
1669 time_t WXDLLIMPEXP_BASE
wxFileModificationTime(const wxString
& filename
)
1672 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1675 return mtime
.GetTicks();
1678 #endif // wxUSE_DATETIME
1681 // Parses the filterStr, returning the number of filters.
1682 // Returns 0 if none or if there's a problem.
1683 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1685 int WXDLLIMPEXP_BASE
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1686 wxArrayString
& descriptions
,
1687 wxArrayString
& filters
)
1689 descriptions
.Clear();
1692 wxString
str(filterStr
);
1694 wxString description
, filter
;
1696 while( pos
!= wxNOT_FOUND
)
1698 pos
= str
.Find(wxT('|'));
1699 if ( pos
== wxNOT_FOUND
)
1701 // if there are no '|'s at all in the string just take the entire
1702 // string as filter and make description empty for later autocompletion
1703 if ( filters
.IsEmpty() )
1705 descriptions
.Add(wxEmptyString
);
1706 filters
.Add(filterStr
);
1710 wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
1716 description
= str
.Left(pos
);
1717 str
= str
.Mid(pos
+ 1);
1718 pos
= str
.Find(wxT('|'));
1719 if ( pos
== wxNOT_FOUND
)
1725 filter
= str
.Left(pos
);
1726 str
= str
.Mid(pos
+ 1);
1729 descriptions
.Add(description
);
1730 filters
.Add(filter
);
1733 #if defined(__WXMOTIF__)
1734 // split it so there is one wildcard per entry
1735 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1737 pos
= filters
[i
].Find(wxT(';'));
1738 if (pos
!= wxNOT_FOUND
)
1740 // first split only filters
1741 descriptions
.Insert(descriptions
[i
],i
+1);
1742 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1743 filters
[i
]=filters
[i
].Left(pos
);
1745 // autoreplace new filter in description with pattern:
1746 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1747 // cause split into:
1748 // C/C++ Files(*.cpp)|*.cpp
1749 // C/C++ Files(*.c;*.h)|*.c;*.h
1750 // and next iteration cause another split into:
1751 // C/C++ Files(*.cpp)|*.cpp
1752 // C/C++ Files(*.c)|*.c
1753 // C/C++ Files(*.h)|*.h
1754 for ( size_t k
=i
;k
<i
+2;k
++ )
1756 pos
= descriptions
[k
].Find(filters
[k
]);
1757 if (pos
!= wxNOT_FOUND
)
1759 wxString before
= descriptions
[k
].Left(pos
);
1760 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1761 pos
= before
.Find(wxT('('),true);
1762 if (pos
>before
.Find(wxT(')'),true))
1764 before
= before
.Left(pos
+1);
1765 before
<< filters
[k
];
1766 pos
= after
.Find(wxT(')'));
1767 int pos1
= after
.Find(wxT('('));
1768 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1770 before
<< after
.Mid(pos
);
1771 descriptions
[k
] = before
;
1781 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1783 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1785 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1789 return filters
.GetCount();
1792 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1793 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1795 // quoting the MSDN: "To obtain a handle to a directory, call the
1796 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1797 // doesn't work under Win9x/ME but then it's not needed there anyhow
1798 const DWORD dwAttr
= ::GetFileAttributes(path
.fn_str());
1799 if ( dwAttr
== INVALID_FILE_ATTRIBUTES
)
1801 // file probably doesn't exist at all
1805 if ( wxGetOsVersion() == wxOS_WINDOWS_9X
)
1807 // FAT directories always allow all access, even if they have the
1808 // readonly flag set, and FAT files can only be read-only
1809 return (dwAttr
& FILE_ATTRIBUTE_DIRECTORY
) ||
1810 (access
!= GENERIC_WRITE
||
1811 !(dwAttr
& FILE_ATTRIBUTE_READONLY
));
1814 HANDLE h
= ::CreateFile
1818 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1821 dwAttr
& FILE_ATTRIBUTE_DIRECTORY
1822 ? FILE_FLAG_BACKUP_SEMANTICS
1826 if ( h
!= INVALID_HANDLE_VALUE
)
1829 return h
!= INVALID_HANDLE_VALUE
;
1831 #endif // __WINDOWS__
1833 bool wxIsWritable(const wxString
&path
)
1835 #if defined( __UNIX__ ) || defined(__OS2__)
1836 // access() will take in count also symbolic links
1837 return wxAccess(path
.c_str(), W_OK
) == 0;
1838 #elif defined( __WINDOWS__ )
1839 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1847 bool wxIsReadable(const wxString
&path
)
1849 #if defined( __UNIX__ ) || defined(__OS2__)
1850 // access() will take in count also symbolic links
1851 return wxAccess(path
.c_str(), R_OK
) == 0;
1852 #elif defined( __WINDOWS__ )
1853 return wxCheckWin32Permission(path
, GENERIC_READ
);
1861 bool wxIsExecutable(const wxString
&path
)
1863 #if defined( __UNIX__ ) || defined(__OS2__)
1864 // access() will take in count also symbolic links
1865 return wxAccess(path
.c_str(), X_OK
) == 0;
1866 #elif defined( __WINDOWS__ )
1867 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1875 // Return the type of an open file
1877 // Some file types on some platforms seem seekable but in fact are not.
1878 // The main use of this function is to allow such cases to be detected
1879 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1881 // This is important for the archive streams, which benefit greatly from
1882 // being able to seek on a stream, but which will produce corrupt archives
1883 // if they unknowingly seek on a non-seekable stream.
1885 // wxFILE_KIND_DISK is a good catch all return value, since other values
1886 // disable features of the archive streams. Some other value must be returned
1887 // for a file type that appears seekable but isn't.
1890 // * Pipes on Windows
1891 // * Files on VMS with a record format other than StreamLF
1893 wxFileKind
wxGetFileKind(int fd
)
1895 #if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1896 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1898 case FILE_TYPE_CHAR
:
1899 return wxFILE_KIND_TERMINAL
;
1900 case FILE_TYPE_DISK
:
1901 return wxFILE_KIND_DISK
;
1902 case FILE_TYPE_PIPE
:
1903 return wxFILE_KIND_PIPE
;
1906 return wxFILE_KIND_UNKNOWN
;
1908 #elif defined(__UNIX__)
1910 return wxFILE_KIND_TERMINAL
;
1915 if (S_ISFIFO(st
.st_mode
))
1916 return wxFILE_KIND_PIPE
;
1917 if (!S_ISREG(st
.st_mode
))
1918 return wxFILE_KIND_UNKNOWN
;
1920 #if defined(__VMS__)
1921 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1922 return wxFILE_KIND_UNKNOWN
;
1925 return wxFILE_KIND_DISK
;
1928 #define wxFILEKIND_STUB
1930 return wxFILE_KIND_DISK
;
1934 wxFileKind
wxGetFileKind(FILE *fp
)
1936 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1937 // Should be fixed in version 1.4.
1938 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1940 return wxFILE_KIND_DISK
;
1941 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WINE__)
1942 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1944 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1949 //------------------------------------------------------------------------
1950 // wild character routines
1951 //------------------------------------------------------------------------
1953 bool wxIsWild( const wxString
& pattern
)
1955 for ( wxString::const_iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
)
1957 switch ( (*p
).GetValue() )
1966 if ( ++p
== pattern
.end() )
1974 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1976 * The match procedure is public domain code (from ircII's reg.c)
1977 * but modified to suit our tastes (RN: No "%" syntax I guess)
1980 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1984 /* Match if both are empty. */
1988 const wxChar
*m
= pat
.c_str(),
1996 if (dot_special
&& (*n
== wxT('.')))
1998 /* Never match so that hidden Unix files
1999 * are never found. */
2012 else if (*m
== wxT('?'))
2020 if (*m
== wxT('\\'))
2023 /* Quoting "nothing" is a bad thing */
2030 * If we are out of both strings or we just
2031 * saw a wildcard, then we can say we have a
2042 * We could check for *n == NULL at this point, but
2043 * since it's more common to have a character there,
2044 * check to see if they match first (m and n) and
2045 * then if they don't match, THEN we can check for
2061 * If there are no more characters in the
2062 * string, but we still need to find another
2063 * character (*m != NULL), then it will be
2064 * impossible to match it
2083 #pragma warning(default:4706) // assignment within conditional expression