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
)
738 return wxFileName(path
).GetFullName();
741 // Return just the directory, or NULL if no directory
743 wxPathOnly (wxChar
*path
)
747 static wxChar buf
[_MAXPATHLEN
];
750 wxStrcpy (buf
, path
);
752 int l
= wxStrlen(path
);
755 // Search backward for a backward or forward slash
758 // Unix like or Windows
759 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
765 if (path
[i
] == wxT(']'))
774 #if defined(__WXMSW__) || defined(__OS2__)
775 // Try Drive specifier
776 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
778 // A:junk --> A:. (since A:.\junk Not A:\junk)
788 // Return just the directory, or NULL if no directory
789 wxString
wxPathOnly (const wxString
& path
)
793 wxChar buf
[_MAXPATHLEN
];
798 int l
= path
.length();
801 // Search backward for a backward or forward slash
804 // Unix like or Windows
805 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
807 // Don't return an empty string
811 return wxString(buf
);
814 if (path
[i
] == wxT(']'))
817 return wxString(buf
);
823 #if defined(__WXMSW__) || defined(__OS2__)
824 // Try Drive specifier
825 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
827 // A:junk --> A:. (since A:.\junk Not A:\junk)
830 return wxString(buf
);
834 return wxEmptyString
;
837 // Utility for converting delimiters in DOS filenames to UNIX style
838 // and back again - or we get nasty problems with delimiters.
839 // Also, convert to lower case, since case is significant in UNIX.
841 #if defined(__WXMAC__) && !defined(__WXOSX_IPHONE__)
843 #define kDefaultPathStyle kCFURLPOSIXPathStyle
845 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
848 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
849 if ( additionalPathComponent
)
851 CFURLRef parentURLRef
= fullURLRef
;
852 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
853 additionalPathComponent
,false);
854 CFRelease( parentURLRef
) ;
856 CFStringRef cfString
= CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
);
857 CFRelease( fullURLRef
) ;
858 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfString
);
859 CFRelease( cfString
);
860 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
861 return wxCFStringRef(cfMutableString
).AsString();
864 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
866 OSStatus err
= noErr
;
867 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(path
));
868 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
869 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
870 CFRelease( cfMutableString
);
873 if ( CFURLGetFSRef(url
, fsRef
) == false )
884 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
886 CFStringRef cfname
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
889 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfname
);
891 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
892 return wxCFStringRef(cfMutableString
).AsString() ;
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(__WXMSW__) || 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(__WXMSW__) || 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__) || defined(__PALMOS__)) && \
1009 wxDoCopyFile(wxFile
& fileIn
,
1010 const wxStructStat
& fbuf
,
1011 const wxString
& filenameDst
,
1014 // reset the umask as we want to create the file with exactly the same
1015 // permissions as the original one
1018 // create file2 with the same permissions than file1 and open it for
1022 if ( !fileOut
.Create(filenameDst
, overwrite
, fbuf
.st_mode
& 0777) )
1025 // copy contents of file1 to file2
1029 ssize_t count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1030 if ( count
== wxInvalidOffset
)
1037 if ( fileOut
.Write(buf
, count
) < (size_t)count
)
1041 // we can expect fileIn to be closed successfully, but we should ensure
1042 // that fileOut was closed as some write errors (disk full) might not be
1043 // detected before doing this
1044 return fileIn
.Close() && fileOut
.Close();
1047 #endif // generic implementation of wxCopyFile
1051 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1053 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1054 // CopyFile() copies file attributes and modification time too, so use it
1055 // instead of our code if available
1057 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1058 if ( !::CopyFile(file1
.t_str(), file2
.t_str(), !overwrite
) )
1060 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1061 file1
.c_str(), file2
.c_str());
1065 #elif defined(__OS2__)
1066 if ( ::DosCopy(file1
.c_str(), file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1068 #elif defined(__PALMOS__)
1069 // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
1071 #elif wxUSE_FILE // !Win32
1074 // get permissions of file1
1075 if ( wxStat( file1
, &fbuf
) != 0 )
1077 // the file probably doesn't exist or we haven't the rights to read
1079 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1084 // open file1 for reading
1085 wxFile
fileIn(file1
, wxFile::read
);
1086 if ( !fileIn
.IsOpened() )
1089 // remove file2, if it exists. This is needed for creating
1090 // file2 with the correct permissions in the next step
1091 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1093 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1098 wxDoCopyFile(fileIn
, fbuf
, file2
, overwrite
);
1100 #if defined(__WXMAC__) || defined(__WXCOCOA__)
1101 // copy the resource fork of the file too if it's present
1102 wxString pathRsrcOut
;
1106 // suppress error messages from this block as resource forks don't have
1110 // it's not enough to check for file existence: it always does on HFS
1111 // but is empty for files without resources
1112 if ( fileRsrcIn
.Open(file1
+ wxT("/..namedfork/rsrc")) &&
1113 fileRsrcIn
.Length() > 0 )
1115 // we must be using HFS or another filesystem with resource fork
1116 // support, suppose that destination file system also is HFS[-like]
1117 pathRsrcOut
= file2
+ wxT("/..namedfork/rsrc");
1119 else // check if we have resource fork in separate file (non-HFS case)
1121 wxFileName
fnRsrc(file1
);
1122 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1125 if ( fileRsrcIn
.Open( fnRsrc
.GetFullPath() ) )
1128 fnRsrc
.SetName(wxT("._") + fnRsrc
.GetName());
1130 pathRsrcOut
= fnRsrc
.GetFullPath();
1135 if ( !pathRsrcOut
.empty() )
1137 if ( !wxDoCopyFile(fileRsrcIn
, fbuf
, pathRsrcOut
, overwrite
) )
1140 #endif // wxMac || wxCocoa
1142 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1143 // no chmod in VA. Should be some permission API for HPFS386 partitions
1145 if ( chmod(file2
.fn_str(), fbuf
.st_mode
) != 0 )
1147 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1151 #endif // OS/2 || Mac
1153 #else // !Win32 && ! wxUSE_FILE
1155 // impossible to simulate with wxWidgets API
1158 wxUnusedVar(overwrite
);
1161 #endif // __WXMSW__ && __WIN32__
1167 wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1169 if ( !overwrite
&& wxFileExists(file2
) )
1173 _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
1174 file1
.c_str(), file2
.c_str()
1180 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
1181 // Normal system call
1182 if ( wxRename (file1
, file2
) == 0 )
1187 if (wxCopyFile(file1
, file2
, overwrite
)) {
1188 wxRemoveFile(file1
);
1195 bool wxRemoveFile(const wxString
& file
)
1197 #if defined(__VISUALC__) \
1198 || defined(__BORLANDC__) \
1199 || defined(__WATCOMC__) \
1200 || defined(__DMC__) \
1201 || defined(__GNUWIN32__) \
1202 || (defined(__MWERKS__) && defined(__MSL__))
1203 int res
= wxRemove(file
);
1204 #elif defined(__WXMAC__)
1205 int res
= unlink(file
.fn_str());
1206 #elif defined(__WXPALMOS__)
1208 // TODO with VFSFileDelete()
1210 int res
= unlink(file
.fn_str());
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(_("Can not 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 #if defined(__OS2__)
1547 ::DosSetDefaultDisk(wxToupper(d
[0]) - wxT('A') + 1);
1548 // do not call DosSetCurrentDir when just changing drive,
1549 // since it requires e.g. "d:." instead of "d:"!
1550 if (d
.length() == 2)
1553 return (::DosSetCurrentDir(d
.c_str()) == 0);
1554 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1555 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1556 #elif defined(__WINDOWS__)
1560 // No equivalent in WinCE
1564 return (bool)(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 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1593 // Get the OS directory if appropriate (such as the Windows directory).
1594 // On non-Windows platform, probably just return the empty string.
1595 wxString
wxGetOSDirectory()
1598 return wxString(wxT("\\Windows"));
1599 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1601 GetWindowsDirectory(buf
, 256);
1602 return wxString(buf
);
1603 #elif defined(__WXMAC__) && wxOSX_USE_CARBON
1604 return wxMacFindFolderNoSeparator(kOnSystemDisk
, 'macs', false);
1606 return wxEmptyString
;
1610 bool wxEndsWithPathSeparator(const wxString
& filename
)
1612 return !filename
.empty() && wxIsPathSeparator(filename
.Last());
1615 // find a file in a list of directories, returns false if not found
1616 bool wxFindFileInPath(wxString
*pStr
, const wxString
& szPath
, const wxString
& szFile
)
1618 // we assume that it's not empty
1619 wxCHECK_MSG( !szFile
.empty(), false,
1620 wxT("empty file name in wxFindFileInPath"));
1622 // skip path separator in the beginning of the file name if present
1624 if ( wxIsPathSeparator(szFile
[0u]) )
1625 szFile2
= szFile
.Mid(1);
1629 wxStringTokenizer
tkn(szPath
, wxPATH_SEP
);
1631 while ( tkn
.HasMoreTokens() )
1633 wxString strFile
= tkn
.GetNextToken();
1634 if ( !wxEndsWithPathSeparator(strFile
) )
1635 strFile
+= wxFILE_SEP_PATH
;
1638 if ( wxFileExists(strFile
) )
1648 #if WXWIN_COMPATIBILITY_2_8
1649 void WXDLLIMPEXP_BASE
wxSplitPath(const wxString
& fileName
,
1654 wxFileName::SplitPath(fileName
, pstrPath
, pstrName
, pstrExt
);
1656 #endif // #if WXWIN_COMPATIBILITY_2_8
1660 time_t WXDLLIMPEXP_BASE
wxFileModificationTime(const wxString
& filename
)
1663 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1666 return mtime
.GetTicks();
1669 #endif // wxUSE_DATETIME
1672 // Parses the filterStr, returning the number of filters.
1673 // Returns 0 if none or if there's a problem.
1674 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1676 int WXDLLIMPEXP_BASE
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1677 wxArrayString
& descriptions
,
1678 wxArrayString
& filters
)
1680 descriptions
.Clear();
1683 wxString
str(filterStr
);
1685 wxString description
, filter
;
1687 while( pos
!= wxNOT_FOUND
)
1689 pos
= str
.Find(wxT('|'));
1690 if ( pos
== wxNOT_FOUND
)
1692 // if there are no '|'s at all in the string just take the entire
1693 // string as filter and make description empty for later autocompletion
1694 if ( filters
.IsEmpty() )
1696 descriptions
.Add(wxEmptyString
);
1697 filters
.Add(filterStr
);
1701 wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
1707 description
= str
.Left(pos
);
1708 str
= str
.Mid(pos
+ 1);
1709 pos
= str
.Find(wxT('|'));
1710 if ( pos
== wxNOT_FOUND
)
1716 filter
= str
.Left(pos
);
1717 str
= str
.Mid(pos
+ 1);
1720 descriptions
.Add(description
);
1721 filters
.Add(filter
);
1724 #if defined(__WXMOTIF__)
1725 // split it so there is one wildcard per entry
1726 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1728 pos
= filters
[i
].Find(wxT(';'));
1729 if (pos
!= wxNOT_FOUND
)
1731 // first split only filters
1732 descriptions
.Insert(descriptions
[i
],i
+1);
1733 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1734 filters
[i
]=filters
[i
].Left(pos
);
1736 // autoreplace new filter in description with pattern:
1737 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1738 // cause split into:
1739 // C/C++ Files(*.cpp)|*.cpp
1740 // C/C++ Files(*.c;*.h)|*.c;*.h
1741 // and next iteration cause another split into:
1742 // C/C++ Files(*.cpp)|*.cpp
1743 // C/C++ Files(*.c)|*.c
1744 // C/C++ Files(*.h)|*.h
1745 for ( size_t k
=i
;k
<i
+2;k
++ )
1747 pos
= descriptions
[k
].Find(filters
[k
]);
1748 if (pos
!= wxNOT_FOUND
)
1750 wxString before
= descriptions
[k
].Left(pos
);
1751 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1752 pos
= before
.Find(wxT('('),true);
1753 if (pos
>before
.Find(wxT(')'),true))
1755 before
= before
.Left(pos
+1);
1756 before
<< filters
[k
];
1757 pos
= after
.Find(wxT(')'));
1758 int pos1
= after
.Find(wxT('('));
1759 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1761 before
<< after
.Mid(pos
);
1762 descriptions
[k
] = before
;
1772 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1774 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1776 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1780 return filters
.GetCount();
1783 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1784 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1786 // quoting the MSDN: "To obtain a handle to a directory, call the
1787 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1788 // doesn't work under Win9x/ME but then it's not needed there anyhow
1789 const DWORD dwAttr
= ::GetFileAttributes(path
.fn_str());
1790 if ( dwAttr
== INVALID_FILE_ATTRIBUTES
)
1792 // file probably doesn't exist at all
1796 if ( wxGetOsVersion() == wxOS_WINDOWS_9X
)
1798 // FAT directories always allow all access, even if they have the
1799 // readonly flag set, and FAT files can only be read-only
1800 return (dwAttr
& FILE_ATTRIBUTE_DIRECTORY
) ||
1801 (access
!= GENERIC_WRITE
||
1802 !(dwAttr
& FILE_ATTRIBUTE_READONLY
));
1805 HANDLE h
= ::CreateFile
1809 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1812 dwAttr
& FILE_ATTRIBUTE_DIRECTORY
1813 ? FILE_FLAG_BACKUP_SEMANTICS
1817 if ( h
!= INVALID_HANDLE_VALUE
)
1820 return h
!= INVALID_HANDLE_VALUE
;
1822 #endif // __WINDOWS__
1824 bool wxIsWritable(const wxString
&path
)
1826 #if defined( __UNIX__ ) || defined(__OS2__)
1827 // access() will take in count also symbolic links
1828 return wxAccess(path
.c_str(), W_OK
) == 0;
1829 #elif defined( __WINDOWS__ )
1830 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1838 bool wxIsReadable(const wxString
&path
)
1840 #if defined( __UNIX__ ) || defined(__OS2__)
1841 // access() will take in count also symbolic links
1842 return wxAccess(path
.c_str(), R_OK
) == 0;
1843 #elif defined( __WINDOWS__ )
1844 return wxCheckWin32Permission(path
, GENERIC_READ
);
1852 bool wxIsExecutable(const wxString
&path
)
1854 #if defined( __UNIX__ ) || defined(__OS2__)
1855 // access() will take in count also symbolic links
1856 return wxAccess(path
.c_str(), X_OK
) == 0;
1857 #elif defined( __WINDOWS__ )
1858 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1866 // Return the type of an open file
1868 // Some file types on some platforms seem seekable but in fact are not.
1869 // The main use of this function is to allow such cases to be detected
1870 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1872 // This is important for the archive streams, which benefit greatly from
1873 // being able to seek on a stream, but which will produce corrupt archives
1874 // if they unknowingly seek on a non-seekable stream.
1876 // wxFILE_KIND_DISK is a good catch all return value, since other values
1877 // disable features of the archive streams. Some other value must be returned
1878 // for a file type that appears seekable but isn't.
1881 // * Pipes on Windows
1882 // * Files on VMS with a record format other than StreamLF
1884 wxFileKind
wxGetFileKind(int fd
)
1886 #if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1887 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1889 case FILE_TYPE_CHAR
:
1890 return wxFILE_KIND_TERMINAL
;
1891 case FILE_TYPE_DISK
:
1892 return wxFILE_KIND_DISK
;
1893 case FILE_TYPE_PIPE
:
1894 return wxFILE_KIND_PIPE
;
1897 return wxFILE_KIND_UNKNOWN
;
1899 #elif defined(__UNIX__)
1901 return wxFILE_KIND_TERMINAL
;
1906 if (S_ISFIFO(st
.st_mode
))
1907 return wxFILE_KIND_PIPE
;
1908 if (!S_ISREG(st
.st_mode
))
1909 return wxFILE_KIND_UNKNOWN
;
1911 #if defined(__VMS__)
1912 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1913 return wxFILE_KIND_UNKNOWN
;
1916 return wxFILE_KIND_DISK
;
1919 #define wxFILEKIND_STUB
1921 return wxFILE_KIND_DISK
;
1925 wxFileKind
wxGetFileKind(FILE *fp
)
1927 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1928 // Should be fixed in version 1.4.
1929 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1931 return wxFILE_KIND_DISK
;
1932 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__) && !defined(__WINE__)
1933 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1935 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1940 //------------------------------------------------------------------------
1941 // wild character routines
1942 //------------------------------------------------------------------------
1944 bool wxIsWild( const wxString
& pattern
)
1946 for ( wxString::const_iterator p
= pattern
.begin(); p
!= pattern
.end(); ++p
)
1948 switch ( (*p
).GetValue() )
1957 if ( ++p
== pattern
.end() )
1965 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1967 * The match procedure is public domain code (from ircII's reg.c)
1968 * but modified to suit our tastes (RN: No "%" syntax I guess)
1971 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1975 /* Match if both are empty. */
1979 const wxChar
*m
= pat
.c_str(),
1987 if (dot_special
&& (*n
== wxT('.')))
1989 /* Never match so that hidden Unix files
1990 * are never found. */
2003 else if (*m
== wxT('?'))
2011 if (*m
== wxT('\\'))
2014 /* Quoting "nothing" is a bad thing */
2021 * If we are out of both strings or we just
2022 * saw a wildcard, then we can say we have a
2033 * We could check for *n == NULL at this point, but
2034 * since it's more common to have a character there,
2035 * check to see if they match first (m and n) and
2036 * then if they don't match, THEN we can check for
2052 * If there are no more characters in the
2053 * string, but we still need to find another
2054 * character (*m != NULL), then it will be
2055 * impossible to match it
2074 #pragma warning(default:4706) // assignment within conditional expression