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/filename.h"
39 #include "wx/tokenzr.h"
41 // there are just too many of those...
43 #pragma warning(disable:4706) // assignment within conditional expression
50 #if !wxONLY_WATCOM_EARLIER_THAN(1,4)
51 #if !(defined(_MSC_VER) && (_MSC_VER > 800))
56 #if defined(__WXMAC__)
57 #include "wx/mac/private.h" // includes mac headers
61 #include "wx/msw/private.h"
62 #include "wx/msw/mslu.h"
64 // sys/cygwin.h is needed for cygwin_conv_to_full_win32_path()
66 // note that it must be included after <windows.h>
69 #include <sys/cygwin.h>
71 #endif // __GNUWIN32__
73 // io.h is needed for _get_osfhandle()
74 // Already included by filefn.h for many Windows compilers
75 #if defined __MWERKS__ || defined __CYGWIN__
84 // TODO: Borland probably has _wgetcwd as well?
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
94 #define _MAXPATHLEN 1024
98 # include "MoreFilesX.h"
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // MT-FIXME: get rid of this horror and all code using it
106 static wxChar wxFileFunctionsBuffer
[4*_MAXPATHLEN
];
108 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
110 // VisualAge C++ V4.0 cannot have any external linkage const decs
111 // in headers included by more than one primary source
113 const int wxInvalidOffset
= -1;
116 // ----------------------------------------------------------------------------
118 // ----------------------------------------------------------------------------
120 // translate the filenames before passing them to OS functions
121 #define OS_FILENAME(s) (s.fn_str())
123 // ============================================================================
125 // ============================================================================
127 // ----------------------------------------------------------------------------
128 // wrappers around standard POSIX functions
129 // ----------------------------------------------------------------------------
131 #ifdef wxNEED_WX_UNISTD_H
133 WXDLLEXPORT
int wxStat( const wxChar
*file_name
, wxStructStat
*buf
)
135 return stat( wxConvFile
.cWX2MB( file_name
), buf
);
138 WXDLLEXPORT
int wxLstat( const wxChar
*file_name
, wxStructStat
*buf
)
140 return lstat( wxConvFile
.cWX2MB( file_name
), buf
);
143 WXDLLEXPORT
int wxAccess( const wxChar
*pathname
, int mode
)
145 return access( wxConvFile
.cWX2MB( pathname
), mode
);
148 WXDLLEXPORT
int wxOpen( const wxChar
*pathname
, int flags
, mode_t mode
)
150 return open( wxConvFile
.cWX2MB( pathname
), flags
, mode
);
153 #endif // wxNEED_WX_UNISTD_H
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 bool wxPathList::Add(const wxString
& path
)
161 // add a path separator to force wxFileName to interpret it always as a directory
162 // (i.e. if we are called with '/home/user' we want to consider it a folder and
163 // not, as wxFileName would consider, a filename).
164 wxFileName
fn(path
+ wxFileName::GetPathSeparator());
166 // add only normalized relative/absolute paths
167 // NB: we won't do wxPATH_NORM_DOTS in order to avoid problems when trying to
168 // normalize paths which starts with ".." (which can be normalized only if
169 // we use also wxPATH_NORM_ABSOLUTE - which we don't want to use).
170 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
173 wxString toadd
= fn
.GetPath();
174 if (Index(toadd
) == wxNOT_FOUND
)
175 wxArrayString::Add(toadd
); // do not add duplicates
180 void wxPathList::Add(const wxArrayString
&arr
)
182 for (size_t j
=0; j
< arr
.GetCount(); j
++)
186 // Add paths e.g. from the PATH environment variable
187 void wxPathList::AddEnvList (const wxString
& WXUNUSED_IN_WINCE(envVariable
))
189 // No environment variables on WinCE
192 // The space has been removed from the tokenizers, otherwise a
193 // path such as "C:\Program Files" would be split into 2 paths:
194 // "C:\Program" and "Files"; this is true for both Windows and Unix.
196 static const wxChar PATH_TOKS
[] =
197 #if defined(__WINDOWS__) || defined(__OS2__)
198 wxT(";"); // Don't separate with colon in DOS (used for drive)
204 if ( wxGetEnv(envVariable
, &val
) )
206 // split into an array of string the value of the env var
207 wxArrayString arr
= wxStringTokenize(val
, PATH_TOKS
);
208 WX_APPEND_ARRAY(*this, arr
);
210 #endif // !__WXWINCE__
213 // Given a full filename (with path), ensure that that file can
214 // be accessed again USING FILENAME ONLY by adding the path
215 // to the list if not already there.
216 bool wxPathList::EnsureFileAccessible (const wxString
& path
)
218 return Add(wxPathOnly(path
));
221 #if WXWIN_COMPATIBILITY_2_6
222 bool wxPathList::Member (const wxString
& path
) const
224 return Index(path
) != wxNOT_FOUND
;
228 wxString
wxPathList::FindValidPath (const wxString
& file
) const
230 // normalize the given string as it could be a path + a filename
231 // and not only a filename
235 // NB: normalize without making absolute otherwise calling this function with
236 // e.g. "b/c.txt" would result in removing the directory 'b' and the for loop
237 // below would only add to the paths of this list the 'c.txt' part when doing
238 // the existence checks...
239 // NB: we don't use wxPATH_NORM_DOTS here, too (see wxPathList::Add for more info)
240 if (!fn
.Normalize(wxPATH_NORM_TILDE
|wxPATH_NORM_LONG
|wxPATH_NORM_ENV_VARS
))
241 return wxEmptyString
;
243 wxASSERT_MSG(!fn
.IsDir(), wxT("Cannot search for directories; only for files"));
245 strend
= fn
.GetFullName(); // search for the file name and ignore the path part
247 strend
= fn
.GetFullPath();
249 for (size_t i
=0; i
<GetCount(); i
++)
251 wxString strstart
= Item(i
);
252 if (!strstart
.IsEmpty() && strstart
.Last() != wxFileName::GetPathSeparator())
253 strstart
+= wxFileName::GetPathSeparator();
255 if (wxFileExists(strstart
+ strend
))
256 return strstart
+ strend
; // Found!
259 return wxEmptyString
; // Not found
262 wxString
wxPathList::FindAbsoluteValidPath (const wxString
& file
) const
264 wxString f
= FindValidPath(file
);
265 if ( f
.empty() || wxIsAbsolutePath(f
) )
268 wxString buf
= ::wxGetCwd();
270 if ( !wxEndsWithPathSeparator(buf
) )
272 buf
+= wxFILE_SEP_PATH
;
279 // ----------------------------------------------------------------------------
280 // miscellaneous global functions (TOFIX!)
281 // ----------------------------------------------------------------------------
283 static inline wxChar
* MYcopystring(const wxString
& s
)
285 wxChar
* copy
= new wxChar
[s
.length() + 1];
286 return wxStrcpy(copy
, s
.c_str());
289 static inline wxChar
* MYcopystring(const wxChar
* s
)
291 wxChar
* copy
= new wxChar
[wxStrlen(s
) + 1];
292 return wxStrcpy(copy
, s
);
297 wxFileExists (const wxString
& filename
)
299 #if defined(__WXPALMOS__)
301 #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
302 // we must use GetFileAttributes() instead of the ANSI C functions because
303 // it can cope with network (UNC) paths unlike them
304 DWORD ret
= ::GetFileAttributes(filename
);
306 return (ret
!= (DWORD
)-1) && !(ret
& FILE_ATTRIBUTE_DIRECTORY
);
309 #define S_ISREG(mode) ((mode) & S_IFREG)
312 #ifndef wxNEED_WX_UNISTD_H
313 return (wxStat( filename
.fn_str() , &st
) == 0 && S_ISREG(st
.st_mode
))
315 || (errno
== EACCES
) // if access is denied something with that name
316 // exists and is opened in exclusive mode.
320 return wxStat( filename
, &st
) == 0 && S_ISREG(st
.st_mode
);
322 #endif // __WIN32__/!__WIN32__
326 wxIsAbsolutePath (const wxString
& filename
)
328 if (!filename
.empty())
330 #if defined(__WXMAC__) && !defined(__DARWIN__)
331 // Classic or Carbon CodeWarrior like
332 // Carbon with Apple DevTools is Unix like
334 // This seems wrong to me, but there is no fix. since
335 // "MacOS:MyText.txt" is absolute whereas "MyDir:MyText.txt"
336 // is not. Or maybe ":MyDir:MyText.txt" has to be used? RR.
337 if (filename
.Find(':') != wxNOT_FOUND
&& filename
[0] != ':')
340 // Unix like or Windows
341 if (filename
[0] == wxT('/'))
345 if ((filename
[0] == wxT('[') && filename
[1] != wxT('.')))
348 #if defined(__WINDOWS__) || defined(__OS2__)
350 if (filename
[0] == wxT('\\') || (wxIsalpha (filename
[0]) && filename
[1] == wxT(':')))
358 * Strip off any extension (dot something) from end of file,
359 * IF one exists. Inserts zero into buffer.
363 void wxStripExtension(wxChar
*buffer
)
365 int len
= wxStrlen(buffer
);
369 if (buffer
[i
] == wxT('.'))
378 void wxStripExtension(wxString
& buffer
)
380 //RN: Be careful about the handling the case where
381 //buffer.length() == 0
382 for(size_t i
= buffer
.length() - 1; i
!= wxString::npos
; --i
)
384 if (buffer
.GetChar(i
) == wxT('.'))
386 buffer
= buffer
.Left(i
);
392 // Destructive removal of /./ and /../ stuff
393 wxChar
*wxRealPath (wxChar
*path
)
396 static const wxChar SEP
= wxT('\\');
397 wxUnix2DosFilename(path
);
399 static const wxChar SEP
= wxT('/');
401 if (path
[0] && path
[1]) {
402 /* MATTHEW: special case "/./x" */
404 if (path
[2] == SEP
&& path
[1] == wxT('.'))
412 if (p
[1] == wxT('.') && p
[2] == wxT('.') && (p
[3] == SEP
|| p
[3] == wxT('\0')))
415 for (q
= p
- 1; q
>= path
&& *q
!= SEP
; q
--)
420 if (q
[0] == SEP
&& (q
[1] != wxT('.') || q
[2] != wxT('.') || q
[3] != SEP
)
421 && (q
- 1 <= path
|| q
[-1] != SEP
))
424 if (path
[0] == wxT('\0'))
429 #if defined(__WXMSW__) || defined(__OS2__)
430 /* Check that path[2] is NULL! */
431 else if (path
[1] == wxT(':') && !path
[2])
440 else if (p
[1] == wxT('.') && (p
[2] == SEP
|| p
[2] == wxT('\0')))
448 wxString
wxRealPath(const wxString
& path
)
450 wxChar
*buf1
=MYcopystring(path
);
451 wxChar
*buf2
=wxRealPath(buf1
);
459 wxChar
*wxCopyAbsolutePath(const wxString
& filename
)
461 if (filename
.empty())
462 return (wxChar
*) NULL
;
464 if (! wxIsAbsolutePath(wxExpandPath(wxFileFunctionsBuffer
, filename
)))
466 wxString buf
= ::wxGetCwd();
467 wxChar ch
= buf
.Last();
469 if (ch
!= wxT('\\') && ch
!= wxT('/'))
475 buf
<< wxFileFunctionsBuffer
;
476 buf
= wxRealPath( buf
);
477 return MYcopystring( buf
);
479 return MYcopystring( wxFileFunctionsBuffer
);
485 ~user/ => user's home dir
486 If the environment variable a = "foo" and b = "bar" then:
503 /* input name in name, pathname output to buf. */
505 wxChar
*wxExpandPath(wxChar
*buf
, const wxChar
*name
)
507 register wxChar
*d
, *s
, *nm
;
508 wxChar lnm
[_MAXPATHLEN
];
511 // Some compilers don't like this line.
512 // const wxChar trimchars[] = wxT("\n \t");
515 trimchars
[0] = wxT('\n');
516 trimchars
[1] = wxT(' ');
517 trimchars
[2] = wxT('\t');
521 const wxChar SEP
= wxT('\\');
523 const wxChar SEP
= wxT('/');
526 if (name
== NULL
|| *name
== wxT('\0'))
528 nm
= MYcopystring(name
); // Make a scratch copy
531 /* Skip leading whitespace and cr */
532 while (wxStrchr((wxChar
*)trimchars
, *nm
) != NULL
)
534 /* And strip off trailing whitespace and cr */
535 s
= nm
+ (q
= wxStrlen(nm
)) - 1;
536 while (q
-- && wxStrchr((wxChar
*)trimchars
, *s
) != NULL
)
544 q
= nm
[0] == wxT('\\') && nm
[1] == wxT('~');
547 /* Expand inline environment variables */
565 while ((*d
++ = *s
) != 0) {
567 if (*s
== wxT('\\')) {
568 if ((*(d
- 1) = *++s
)!=0) {
576 // No env variables on WinCE
579 if (*s
++ == wxT('$') && (*s
== wxT('{') || *s
== wxT(')')))
581 if (*s
++ == wxT('$'))
584 register wxChar
*start
= d
;
585 register int braces
= (*s
== wxT('{') || *s
== wxT('('));
586 register wxChar
*value
;
587 while ((*d
++ = *s
) != 0)
588 if (braces
? (*s
== wxT('}') || *s
== wxT(')')) : !(wxIsalnum(*s
) || *s
== wxT('_')) )
593 value
= wxGetenv(braces
? start
+ 1 : start
);
595 for ((d
= start
- 1); (*d
++ = *value
++) != 0;)
609 /* Expand ~ and ~user */
611 if (nm
[0] == wxT('~') && !q
)
614 if (nm
[1] == SEP
|| nm
[1] == 0)
616 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
617 if ((s
= WXSTRINGCAST
wxGetUserHome(wxEmptyString
)) != NULL
) {
622 { /* ~user/filename */
623 register wxChar
*nnm
;
624 register wxChar
*home
;
625 for (s
= nm
; *s
&& *s
!= SEP
; s
++)
629 int was_sep
; /* MATTHEW: Was there a separator, or NULL? */
630 was_sep
= (*s
== SEP
);
631 nnm
= *s
? s
+ 1 : s
;
633 // FIXME: wxGetUserHome could return temporary storage in Unicode mode
634 if ((home
= WXSTRINGCAST
wxGetUserHome(wxString(nm
+ 1))) == NULL
)
636 if (was_sep
) /* replace only if it was there: */
649 if (s
&& *s
) { /* MATTHEW: s could be NULL if user '~' didn't exist */
651 while (wxT('\0') != (*d
++ = *s
++))
654 if (d
- 1 > buf
&& *(d
- 2) != SEP
)
658 while ((*d
++ = *s
++) != 0)
662 delete[] nm_tmp
; // clean up alloc
663 /* Now clean up the buffer */
664 return wxRealPath(buf
);
667 /* Contract Paths to be build upon an environment variable
670 example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib
672 The call wxExpandPath can convert these back!
675 wxContractPath (const wxString
& filename
,
676 const wxString
& WXUNUSED_IN_WINCE(envname
),
677 const wxString
& user
)
679 static wxChar dest
[_MAXPATHLEN
];
681 if (filename
.empty())
682 return (wxChar
*) NULL
;
684 wxStrcpy (dest
, WXSTRINGCAST filename
);
686 wxUnix2DosFilename(dest
);
689 // Handle environment
693 if (!envname
.empty() && (val
= wxGetenv (WXSTRINGCAST envname
)) != NULL
&&
694 (tcp
= wxStrstr (dest
, val
)) != NULL
)
696 wxStrcpy (wxFileFunctionsBuffer
, tcp
+ wxStrlen (val
));
699 wxStrcpy (tcp
, WXSTRINGCAST envname
);
700 wxStrcat (tcp
, wxT("}"));
701 wxStrcat (tcp
, wxFileFunctionsBuffer
);
705 // Handle User's home (ignore root homes!)
706 val
= wxGetUserHome (user
);
710 const size_t len
= wxStrlen(val
);
714 if (wxStrncmp(dest
, val
, len
) == 0)
716 wxStrcpy(wxFileFunctionsBuffer
, wxT("~"));
718 wxStrcat(wxFileFunctionsBuffer
, (const wxChar
*) user
);
719 wxStrcat(wxFileFunctionsBuffer
, dest
+ len
);
720 wxStrcpy (dest
, wxFileFunctionsBuffer
);
726 // Return just the filename, not the path (basename)
727 wxChar
*wxFileNameFromPath (wxChar
*path
)
730 wxString n
= wxFileNameFromPath(p
);
732 return path
+ p
.length() - n
.length();
735 wxString
wxFileNameFromPath (const wxString
& path
)
738 wxFileName::SplitPath(path
, NULL
, &name
, &ext
);
740 wxString fullname
= name
;
743 fullname
<< wxFILE_SEP_EXT
<< ext
;
749 // Return just the directory, or NULL if no directory
751 wxPathOnly (wxChar
*path
)
755 static wxChar buf
[_MAXPATHLEN
];
758 wxStrcpy (buf
, path
);
760 int l
= wxStrlen(path
);
763 // Search backward for a backward or forward slash
766 #if defined(__WXMAC__) && !defined(__DARWIN__)
767 // Classic or Carbon CodeWarrior like
768 // Carbon with Apple DevTools is Unix like
769 if (path
[i
] == wxT(':') )
775 // Unix like or Windows
776 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
783 if (path
[i
] == wxT(']'))
792 #if defined(__WXMSW__) || defined(__OS2__)
793 // Try Drive specifier
794 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
796 // A:junk --> A:. (since A:.\junk Not A:\junk)
803 return (wxChar
*) NULL
;
806 // Return just the directory, or NULL if no directory
807 wxString
wxPathOnly (const wxString
& path
)
811 wxChar buf
[_MAXPATHLEN
];
814 wxStrcpy (buf
, WXSTRINGCAST path
);
816 int l
= path
.length();
819 // Search backward for a backward or forward slash
822 #if defined(__WXMAC__) && !defined(__DARWIN__)
823 // Classic or Carbon CodeWarrior like
824 // Carbon with Apple DevTools is Unix like
825 if (path
[i
] == wxT(':') )
828 return wxString(buf
);
831 // Unix like or Windows
832 if (path
[i
] == wxT('/') || path
[i
] == wxT('\\'))
834 // Don't return an empty string
838 return wxString(buf
);
842 if (path
[i
] == wxT(']'))
845 return wxString(buf
);
851 #if defined(__WXMSW__) || defined(__OS2__)
852 // Try Drive specifier
853 if (wxIsalpha (buf
[0]) && buf
[1] == wxT(':'))
855 // A:junk --> A:. (since A:.\junk Not A:\junk)
858 return wxString(buf
);
862 return wxEmptyString
;
865 // Utility for converting delimiters in DOS filenames to UNIX style
866 // and back again - or we get nasty problems with delimiters.
867 // Also, convert to lower case, since case is significant in UNIX.
869 #if defined(__WXMAC__)
871 #if TARGET_API_MAC_OSX
872 #define kDefaultPathStyle kCFURLPOSIXPathStyle
874 #define kDefaultPathStyle kCFURLHFSPathStyle
877 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
)
880 fullURLRef
= CFURLCreateFromFSRef(NULL
, fsRef
);
881 if ( additionalPathComponent
)
883 CFURLRef parentURLRef
= fullURLRef
;
884 fullURLRef
= CFURLCreateCopyAppendingPathComponent(NULL
, parentURLRef
,
885 additionalPathComponent
,false);
886 CFRelease( parentURLRef
) ;
888 CFStringRef cfString
= CFURLCopyFileSystemPath(fullURLRef
, kDefaultPathStyle
);
889 CFRelease( fullURLRef
) ;
890 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfString
);
891 CFRelease( cfString
);
892 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
893 return wxMacCFStringHolder(cfMutableString
).AsString();
896 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
)
898 OSStatus err
= noErr
;
899 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, wxMacCFStringHolder(path
));
900 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
901 CFURLRef url
= CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kDefaultPathStyle
, false);
902 CFRelease( cfMutableString
);
905 if ( CFURLGetFSRef(url
, fsRef
) == false )
916 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
)
918 CFStringRef cfname
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
921 CFMutableStringRef cfMutableString
= CFStringCreateMutableCopy(NULL
, 0, cfname
);
923 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormC
);
924 return wxMacCFStringHolder(cfMutableString
).AsString() ;
929 wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
)
932 if ( FSpMakeFSRef( spec
, &fsRef
) == noErr
)
934 return wxMacFSRefToPath( &fsRef
) ;
936 return wxEmptyString
;
939 void wxMacFilename2FSSpec( const wxString
& path
, FSSpec
*spec
)
941 OSStatus err
= noErr
;
943 wxMacPathToFSRef( path
, &fsRef
) ;
944 err
= FSRefMakeFSSpec( &fsRef
, spec
) ;
951 wxDos2UnixFilename (wxChar
*s
)
960 *s
= (wxChar
)wxTolower (*s
); // Case INDEPENDENT
967 #if defined(__WXMSW__) || defined(__OS2__)
968 wxUnix2DosFilename (wxChar
*s
)
970 wxUnix2DosFilename (wxChar
*WXUNUSED(s
) )
973 // Yes, I really mean this to happen under DOS only! JACS
974 #if defined(__WXMSW__) || defined(__OS2__)
985 // Concatenate two files to form third
987 wxConcatFiles (const wxString
& file1
, const wxString
& file2
, const wxString
& file3
)
991 wxFile
in1(file1
), in2(file2
);
992 wxTempFile
out(file3
);
994 if ( !in1
.IsOpened() || !in2
.IsOpened() || !out
.IsOpened() )
998 unsigned char buf
[1024];
1000 for( int i
=0; i
<2; i
++)
1002 wxFile
*in
= i
==0 ? &in1
: &in2
;
1004 if ( (ofs
= in
->Read(buf
,WXSIZEOF(buf
))) == wxInvalidOffset
) return false;
1006 if ( !out
.Write(buf
,ofs
) )
1008 } while ( ofs
== (ssize_t
)WXSIZEOF(buf
) );
1011 return out
.Commit();
1025 wxCopyFile (const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1027 #if defined(__WIN32__) && !defined(__WXMICROWIN__)
1028 // CopyFile() copies file attributes and modification time too, so use it
1029 // instead of our code if available
1031 // NB: 3rd parameter is bFailIfExists i.e. the inverse of overwrite
1032 if ( !::CopyFile(file1
, file2
, !overwrite
) )
1034 wxLogSysError(_("Failed to copy the file '%s' to '%s'"),
1035 file1
.c_str(), file2
.c_str());
1039 #elif defined(__OS2__)
1040 if ( ::DosCopy((PSZ
)file1
.c_str(), (PSZ
)file2
.c_str(), overwrite
? DCPY_EXISTING
: 0) != 0 )
1042 #elif defined(__PALMOS__)
1043 // TODO with http://www.palmos.com/dev/support/docs/protein_books/Memory_Databases_Files/
1045 #elif wxUSE_FILE // !Win32
1048 // get permissions of file1
1049 if ( wxStat( file1
.c_str(), &fbuf
) != 0 )
1051 // the file probably doesn't exist or we haven't the rights to read
1053 wxLogSysError(_("Impossible to get permissions for file '%s'"),
1058 // open file1 for reading
1059 wxFile
fileIn(file1
, wxFile::read
);
1060 if ( !fileIn
.IsOpened() )
1063 // remove file2, if it exists. This is needed for creating
1064 // file2 with the correct permissions in the next step
1065 if ( wxFileExists(file2
) && (!overwrite
|| !wxRemoveFile(file2
)))
1067 wxLogSysError(_("Impossible to overwrite the file '%s'"),
1072 // reset the umask as we want to create the file with exactly the same
1073 // permissions as the original one
1076 // create file2 with the same permissions than file1 and open it for
1080 if ( !fileOut
.Create(file2
, overwrite
, fbuf
.st_mode
& 0777) )
1083 // copy contents of file1 to file2
1088 count
= fileIn
.Read(buf
, WXSIZEOF(buf
));
1089 if ( fileIn
.Error() )
1096 if ( fileOut
.Write(buf
, count
) < count
)
1100 // we can expect fileIn to be closed successfully, but we should ensure
1101 // that fileOut was closed as some write errors (disk full) might not be
1102 // detected before doing this
1103 if ( !fileIn
.Close() || !fileOut
.Close() )
1106 #if !defined(__VISAGECPP__) && !defined(__WXMAC__) || defined(__UNIX__)
1107 // no chmod in VA. Should be some permission API for HPFS386 partitions
1109 if ( chmod(OS_FILENAME(file2
), fbuf
.st_mode
) != 0 )
1111 wxLogSysError(_("Impossible to set permissions for the file '%s'"),
1115 #endif // OS/2 || Mac
1117 #else // !Win32 && ! wxUSE_FILE
1119 // impossible to simulate with wxWidgets API
1122 wxUnusedVar(overwrite
);
1125 #endif // __WXMSW__ && __WIN32__
1131 wxRenameFile(const wxString
& file1
, const wxString
& file2
, bool overwrite
)
1133 if ( !overwrite
&& wxFileExists(file2
) )
1137 _("Failed to rename the file '%s' to '%s' because the destination file already exists."),
1138 file1
.c_str(), file2
.c_str()
1144 #if !defined(__WXWINCE__) && !defined(__WXPALMOS__)
1145 // Normal system call
1146 if ( wxRename (file1
, file2
) == 0 )
1151 if (wxCopyFile(file1
, file2
, overwrite
)) {
1152 wxRemoveFile(file1
);
1159 bool wxRemoveFile(const wxString
& file
)
1161 #if defined(__VISUALC__) \
1162 || defined(__BORLANDC__) \
1163 || defined(__WATCOMC__) \
1164 || defined(__DMC__) \
1165 || defined(__GNUWIN32__) \
1166 || (defined(__MWERKS__) && defined(__MSL__))
1167 int res
= wxRemove(file
);
1168 #elif defined(__WXMAC__)
1169 int res
= unlink(wxFNCONV(file
));
1170 #elif defined(__WXPALMOS__)
1172 // TODO with VFSFileDelete()
1174 int res
= unlink(OS_FILENAME(file
));
1180 bool wxMkdir(const wxString
& dir
, int perm
)
1182 #if defined(__WXPALMOS__)
1184 #elif defined(__WXMAC__) && !defined(__UNIX__)
1185 return (mkdir( wxFNCONV(dir
) , 0 ) == 0);
1187 const wxChar
*dirname
= dir
.c_str();
1189 // assume mkdir() has 2 args on non Windows-OS/2 platforms and on Windows too
1190 // for the GNU compiler
1191 #if (!(defined(__WXMSW__) || defined(__OS2__) || defined(__DOS__))) || (defined(__GNUWIN32__) && !defined(__MINGW32__)) || defined(__WINE__) || defined(__WXMICROWIN__)
1194 if ( mkdir(wxFNCONV(dirname
)) != 0 )
1196 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1198 #elif defined(__OS2__)
1200 if (::DosCreateDir((PSZ
)dirname
, NULL
) != 0) // enhance for EAB's??
1201 #elif defined(__DOS__)
1202 #if defined(__WATCOMC__)
1204 if ( wxMkDir(wxFNSTRINGCAST
wxFNCONV(dirname
)) != 0 )
1205 #elif defined(__DJGPP__)
1206 if ( mkdir(wxFNCONV(dirname
), perm
) != 0 )
1208 #error "Unsupported DOS compiler!"
1210 #else // !MSW, !DOS and !OS/2 VAC++
1213 if ( !CreateDirectory(dirname
, NULL
) )
1215 if ( wxMkDir(dir
.fn_str()) != 0 )
1219 wxLogSysError(_("Directory '%s' couldn't be created"), dirname
);
1228 bool wxRmdir(const wxString
& dir
, int WXUNUSED(flags
))
1230 #if defined(__VMS__)
1231 return false; //to be changed since rmdir exists in VMS7.x
1232 #elif defined(__OS2__)
1233 return (::DosDeleteDir((PSZ
)dir
.c_str()) == 0);
1234 #elif defined(__WXWINCE__)
1235 return (CreateDirectory(dir
, NULL
) != 0);
1236 #elif defined(__WXPALMOS__)
1237 // TODO with VFSFileRename()
1240 return (wxRmDir(OS_FILENAME(dir
)) == 0);
1244 // does the path exists? (may have or not '/' or '\\' at the end)
1245 bool wxDirExists(const wxChar
*pszPathName
)
1247 wxString
strPath(pszPathName
);
1249 #if defined(__WINDOWS__) || defined(__OS2__)
1250 // Windows fails to find directory named "c:\dir\" even if "c:\dir" exists,
1251 // so remove all trailing backslashes from the path - but don't do this for
1252 // the paths "d:\" (which are different from "d:") nor for just "\"
1253 while ( wxEndsWithPathSeparator(strPath
) )
1255 size_t len
= strPath
.length();
1256 if ( len
== 1 || (len
== 3 && strPath
[len
- 2] == _T(':')) )
1259 strPath
.Truncate(len
- 1);
1261 #endif // __WINDOWS__
1264 // OS/2 can't handle "d:", it wants either "d:\" or "d:."
1265 if (strPath
.length() == 2 && strPath
[1u] == _T(':'))
1269 #if defined(__WXPALMOS__)
1271 #elif defined(__WIN32__) && !defined(__WXMICROWIN__)
1272 // stat() can't cope with network paths
1273 DWORD ret
= ::GetFileAttributes(strPath
);
1275 return (ret
!= (DWORD
)-1) && (ret
& FILE_ATTRIBUTE_DIRECTORY
);
1276 #elif defined(__OS2__)
1277 FILESTATUS3 Info
= {{0}};
1278 APIRET rc
= ::DosQueryPathInfo((PSZ
)(WXSTRINGCAST strPath
), FIL_STANDARD
,
1279 (void*) &Info
, sizeof(FILESTATUS3
));
1281 return ((rc
== NO_ERROR
) && (Info
.attrFile
& FILE_DIRECTORY
)) ||
1282 (rc
== ERROR_SHARING_VIOLATION
);
1283 // If we got a sharing violation, there must be something with this name.
1287 #ifndef __VISAGECPP__
1288 return wxStat(strPath
.c_str(), &st
) == 0 && ((st
.st_mode
& S_IFMT
) == S_IFDIR
);
1290 // S_IFMT not supported in VA compilers.. st_mode is a 2byte value only
1291 return wxStat(pszPathName
, &st
) == 0 && (st
.st_mode
== S_IFDIR
);
1294 #endif // __WIN32__/!__WIN32__
1297 // Get a temporary filename, opening and closing the file.
1298 wxChar
*wxGetTempFileName(const wxString
& prefix
, wxChar
*buf
)
1301 if ( !wxGetTempFileName(prefix
, filename
) )
1305 wxStrcpy(buf
, filename
);
1307 buf
= MYcopystring(filename
);
1312 bool wxGetTempFileName(const wxString
& prefix
, wxString
& buf
)
1315 buf
= wxFileName::CreateTempFileName(prefix
);
1317 return !buf
.empty();
1318 #else // !wxUSE_FILE
1319 wxUnusedVar(prefix
);
1323 #endif // wxUSE_FILE/!wxUSE_FILE
1326 // Get first file name matching given wild card.
1328 static wxDir
*gs_dir
= NULL
;
1329 static wxString gs_dirPath
;
1331 wxString
wxFindFirstFile(const wxChar
*spec
, int flags
)
1333 wxSplitPath(spec
, &gs_dirPath
, NULL
, NULL
);
1334 if ( gs_dirPath
.empty() )
1335 gs_dirPath
= wxT(".");
1336 if ( !wxEndsWithPathSeparator(gs_dirPath
) )
1337 gs_dirPath
<< wxFILE_SEP_PATH
;
1341 gs_dir
= new wxDir(gs_dirPath
);
1343 if ( !gs_dir
->IsOpened() )
1345 wxLogSysError(_("Can not enumerate files '%s'"), spec
);
1346 return wxEmptyString
;
1352 case wxDIR
: dirFlags
= wxDIR_DIRS
; break;
1353 case wxFILE
: dirFlags
= wxDIR_FILES
; break;
1354 default: dirFlags
= wxDIR_DIRS
| wxDIR_FILES
; break;
1358 gs_dir
->GetFirst(&result
, wxFileNameFromPath(wxString(spec
)), dirFlags
);
1359 if ( result
.empty() )
1365 return gs_dirPath
+ result
;
1368 wxString
wxFindNextFile()
1370 wxASSERT_MSG( gs_dir
, wxT("You must call wxFindFirstFile before!") );
1373 gs_dir
->GetNext(&result
);
1375 if ( result
.empty() )
1381 return gs_dirPath
+ result
;
1385 // Get current working directory.
1386 // If buf is NULL, allocates space using new, else copies into buf.
1387 // wxGetWorkingDirectory() is obsolete, use wxGetCwd()
1388 // wxDoGetCwd() is their common core to be moved
1389 // to wxGetCwd() once wxGetWorkingDirectory() will be removed.
1390 // Do not expose wxDoGetCwd in headers!
1392 wxChar
*wxDoGetCwd(wxChar
*buf
, int sz
)
1394 #if defined(__WXPALMOS__)
1396 if(buf
&& sz
>0) buf
[0] = _T('\0');
1398 #elif defined(__WXWINCE__)
1400 if(buf
&& sz
>0) buf
[0] = _T('\0');
1405 buf
= new wxChar
[sz
+ 1];
1408 bool ok
wxDUMMY_INITIALIZE(false);
1410 // for the compilers which have Unicode version of _getcwd(), call it
1411 // directly, for the others call the ANSI version and do the translation
1414 #else // wxUSE_UNICODE
1415 bool needsANSI
= true;
1417 #if !defined(HAVE_WGETCWD) || wxUSE_UNICODE_MSLU
1418 char cbuf
[_MAXPATHLEN
];
1422 #if wxUSE_UNICODE_MSLU
1423 if ( wxGetOsVersion() != wxOS_WINDOWS_9X
)
1425 char *cbuf
= NULL
; // never really used because needsANSI will always be false
1428 ok
= _wgetcwd(buf
, sz
) != NULL
;
1434 #endif // wxUSE_UNICODE
1436 #if defined(_MSC_VER) || defined(__MINGW32__)
1437 ok
= _getcwd(cbuf
, sz
) != NULL
;
1438 #elif defined(__WXMAC__) && !defined(__DARWIN__)
1440 if ( getcwd( lbuf
, sizeof( lbuf
) ) )
1442 wxString
res( lbuf
, *wxConvCurrent
) ;
1443 wxStrcpy( buf
, res
) ;
1448 #elif defined(__OS2__)
1450 ULONG ulDriveNum
= 0;
1451 ULONG ulDriveMap
= 0;
1452 rc
= ::DosQueryCurrentDisk(&ulDriveNum
, &ulDriveMap
);
1457 rc
= ::DosQueryCurrentDir( 0 // current drive
1461 cbuf
[0] = char('A' + (ulDriveNum
- 1));
1466 #else // !Win32/VC++ !Mac !OS2
1467 ok
= getcwd(cbuf
, sz
) != NULL
;
1470 #if wxUSE_UNICODE && !(defined(__WXMAC__) && !defined(__DARWIN__))
1471 // finally convert the result to Unicode if needed
1472 wxConvFile
.MB2WC(buf
, cbuf
, sz
);
1473 #endif // wxUSE_UNICODE
1478 wxLogSysError(_("Failed to get the working directory"));
1480 // VZ: the old code used to return "." on error which didn't make any
1481 // sense at all to me - empty string is a better error indicator
1482 // (NULL might be even better but I'm afraid this could lead to
1483 // problems with the old code assuming the return is never NULL)
1486 else // ok, but we might need to massage the path into the right format
1489 // VS: DJGPP is a strange mix of DOS and UNIX API and returns paths
1490 // with / deliminers. We don't like that.
1491 for (wxChar
*ch
= buf
; *ch
; ch
++)
1493 if (*ch
== wxT('/'))
1498 // MBN: we hope that in the case the user is compiling a GTK+/Motif app,
1499 // he needs Unix as opposed to Win32 pathnames
1500 #if defined( __CYGWIN__ ) && defined( __WINDOWS__ )
1501 // another example of DOS/Unix mix (Cygwin)
1502 wxString pathUnix
= buf
;
1504 char bufA
[_MAXPATHLEN
];
1505 cygwin_conv_to_full_win32_path(pathUnix
.mb_str(wxConvFile
), bufA
);
1506 wxConvFile
.MB2WC(buf
, bufA
, sz
);
1508 cygwin_conv_to_full_win32_path(pathUnix
, buf
);
1509 #endif // wxUSE_UNICODE
1510 #endif // __CYGWIN__
1523 #if WXWIN_COMPATIBILITY_2_6
1524 wxChar
*wxGetWorkingDirectory(wxChar
*buf
, int sz
)
1526 return wxDoGetCwd(buf
,sz
);
1528 #endif // WXWIN_COMPATIBILITY_2_6
1533 wxDoGetCwd(wxStringBuffer(str
, _MAXPATHLEN
), _MAXPATHLEN
);
1537 bool wxSetWorkingDirectory(const wxString
& d
)
1539 #if defined(__OS2__)
1540 return (::DosSetCurrentDir((PSZ
)d
.c_str()) == 0);
1541 #elif defined(__UNIX__) || defined(__WXMAC__) || defined(__DOS__)
1542 return (chdir(wxFNSTRINGCAST d
.fn_str()) == 0);
1543 #elif defined(__WINDOWS__)
1547 // No equivalent in WinCE
1551 return (bool)(SetCurrentDirectory(d
) != 0);
1554 // Must change drive, too.
1555 bool isDriveSpec
= ((strlen(d
) > 1) && (d
[1] == ':'));
1558 wxChar firstChar
= d
[0];
1562 firstChar
= firstChar
- 32;
1564 // To a drive number
1565 unsigned int driveNo
= firstChar
- 64;
1568 unsigned int noDrives
;
1569 _dos_setdrive(driveNo
, &noDrives
);
1572 bool success
= (chdir(WXSTRINGCAST d
) == 0);
1580 // Get the OS directory if appropriate (such as the Windows directory).
1581 // On non-Windows platform, probably just return the empty string.
1582 wxString
wxGetOSDirectory()
1585 return wxString(wxT("\\Windows"));
1586 #elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
1588 GetWindowsDirectory(buf
, 256);
1589 return wxString(buf
);
1590 #elif defined(__WXMAC__)
1591 return wxMacFindFolder(kOnSystemDisk
, 'macs', false);
1593 return wxEmptyString
;
1597 bool wxEndsWithPathSeparator(const wxChar
*pszFileName
)
1599 size_t len
= wxStrlen(pszFileName
);
1601 return len
&& wxIsPathSeparator(pszFileName
[len
- 1]);
1604 // find a file in a list of directories, returns false if not found
1605 bool wxFindFileInPath(wxString
*pStr
, const wxChar
*pszPath
, const wxChar
*pszFile
)
1607 // we assume that it's not empty
1608 wxCHECK_MSG( !wxIsEmpty(pszFile
), false,
1609 _T("empty file name in wxFindFileInPath"));
1611 // skip path separator in the beginning of the file name if present
1612 if ( wxIsPathSeparator(*pszFile
) )
1615 // copy the path (strtok will modify it)
1616 wxChar
*szPath
= new wxChar
[wxStrlen(pszPath
) + 1];
1617 wxStrcpy(szPath
, pszPath
);
1620 wxChar
*pc
, *save_ptr
;
1621 for ( pc
= wxStrtok(szPath
, wxPATH_SEP
, &save_ptr
);
1623 pc
= wxStrtok((wxChar
*) NULL
, wxPATH_SEP
, &save_ptr
) )
1625 // search for the file in this directory
1627 if ( !wxEndsWithPathSeparator(pc
) )
1628 strFile
+= wxFILE_SEP_PATH
;
1631 if ( wxFileExists(strFile
) ) {
1637 // suppress warning about unused variable save_ptr when wxStrtok() is a
1638 // macro which throws away its third argument
1643 return pc
!= NULL
; // if true => we breaked from the loop
1646 void WXDLLEXPORT
wxSplitPath(const wxChar
*pszFileName
,
1651 // it can be empty, but it shouldn't be NULL
1652 wxCHECK_RET( pszFileName
, wxT("NULL file name in wxSplitPath") );
1654 wxFileName::SplitPath(pszFileName
, pstrPath
, pstrName
, pstrExt
);
1659 time_t WXDLLEXPORT
wxFileModificationTime(const wxString
& filename
)
1662 if ( !wxFileName(filename
).GetTimes(NULL
, &mtime
, NULL
) )
1665 return mtime
.GetTicks();
1668 #endif // wxUSE_DATETIME
1671 // Parses the filterStr, returning the number of filters.
1672 // Returns 0 if none or if there's a problem.
1673 // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpeg"
1675 int WXDLLEXPORT
wxParseCommonDialogsFilter(const wxString
& filterStr
,
1676 wxArrayString
& descriptions
,
1677 wxArrayString
& filters
)
1679 descriptions
.Clear();
1682 wxString
str(filterStr
);
1684 wxString description
, filter
;
1686 while( pos
!= wxNOT_FOUND
)
1688 pos
= str
.Find(wxT('|'));
1689 if ( pos
== wxNOT_FOUND
)
1691 // if there are no '|'s at all in the string just take the entire
1692 // string as filter and make description empty for later autocompletion
1693 if ( filters
.IsEmpty() )
1695 descriptions
.Add(wxEmptyString
);
1696 filters
.Add(filterStr
);
1700 wxFAIL_MSG( _T("missing '|' in the wildcard string!") );
1706 description
= str
.Left(pos
);
1707 str
= str
.Mid(pos
+ 1);
1708 pos
= str
.Find(wxT('|'));
1709 if ( pos
== wxNOT_FOUND
)
1715 filter
= str
.Left(pos
);
1716 str
= str
.Mid(pos
+ 1);
1719 descriptions
.Add(description
);
1720 filters
.Add(filter
);
1723 #if defined(__WXMOTIF__)
1724 // split it so there is one wildcard per entry
1725 for( size_t i
= 0 ; i
< descriptions
.GetCount() ; i
++ )
1727 pos
= filters
[i
].Find(wxT(';'));
1728 if (pos
!= wxNOT_FOUND
)
1730 // first split only filters
1731 descriptions
.Insert(descriptions
[i
],i
+1);
1732 filters
.Insert(filters
[i
].Mid(pos
+1),i
+1);
1733 filters
[i
]=filters
[i
].Left(pos
);
1735 // autoreplace new filter in description with pattern:
1736 // C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
1737 // cause split into:
1738 // C/C++ Files(*.cpp)|*.cpp
1739 // C/C++ Files(*.c;*.h)|*.c;*.h
1740 // and next iteration cause another split into:
1741 // C/C++ Files(*.cpp)|*.cpp
1742 // C/C++ Files(*.c)|*.c
1743 // C/C++ Files(*.h)|*.h
1744 for ( size_t k
=i
;k
<i
+2;k
++ )
1746 pos
= descriptions
[k
].Find(filters
[k
]);
1747 if (pos
!= wxNOT_FOUND
)
1749 wxString before
= descriptions
[k
].Left(pos
);
1750 wxString after
= descriptions
[k
].Mid(pos
+filters
[k
].Len());
1751 pos
= before
.Find(_T('('),true);
1752 if (pos
>before
.Find(_T(')'),true))
1754 before
= before
.Left(pos
+1);
1755 before
<< filters
[k
];
1756 pos
= after
.Find(_T(')'));
1757 int pos1
= after
.Find(_T('('));
1758 if (pos
!= wxNOT_FOUND
&& (pos
<pos1
|| pos1
==wxNOT_FOUND
))
1760 before
<< after
.Mid(pos
);
1761 descriptions
[k
] = before
;
1771 for( size_t j
= 0 ; j
< descriptions
.GetCount() ; j
++ )
1773 if ( descriptions
[j
].empty() && !filters
[j
].empty() )
1775 descriptions
[j
].Printf(_("Files (%s)"), filters
[j
].c_str());
1779 return filters
.GetCount();
1782 #if defined(__WINDOWS__) && !(defined(__UNIX__) || defined(__OS2__))
1783 static bool wxCheckWin32Permission(const wxString
& path
, DWORD access
)
1785 // quoting the MSDN: "To obtain a handle to a directory, call the
1786 // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this
1787 // doesn't work under Win9x/ME but then it's not needed there anyhow
1788 bool isdir
= wxDirExists(path
);
1789 if ( isdir
&& wxGetOsVersion() == wxOS_WINDOWS_9X
)
1791 // FAT directories always allow all access, even if they have the
1792 // readonly flag set
1796 HANDLE h
= ::CreateFile
1800 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1803 isdir
? FILE_FLAG_BACKUP_SEMANTICS
: 0,
1806 if ( h
!= INVALID_HANDLE_VALUE
)
1809 return h
!= INVALID_HANDLE_VALUE
;
1811 #endif // __WINDOWS__
1813 bool wxIsWritable(const wxString
&path
)
1815 #if defined( __UNIX__ ) || defined(__OS2__)
1816 // access() will take in count also symbolic links
1817 return access(wxConvFile
.cWX2MB(path
), W_OK
) == 0;
1818 #elif defined( __WINDOWS__ )
1819 return wxCheckWin32Permission(path
, GENERIC_WRITE
);
1827 bool wxIsReadable(const wxString
&path
)
1829 #if defined( __UNIX__ ) || defined(__OS2__)
1830 // access() will take in count also symbolic links
1831 return access(wxConvFile
.cWX2MB(path
), R_OK
) == 0;
1832 #elif defined( __WINDOWS__ )
1833 return wxCheckWin32Permission(path
, GENERIC_READ
);
1841 bool wxIsExecutable(const wxString
&path
)
1843 #if defined( __UNIX__ ) || defined(__OS2__)
1844 // access() will take in count also symbolic links
1845 return access(wxConvFile
.cWX2MB(path
), X_OK
) == 0;
1846 #elif defined( __WINDOWS__ )
1847 return wxCheckWin32Permission(path
, GENERIC_EXECUTE
);
1855 // Return the type of an open file
1857 // Some file types on some platforms seem seekable but in fact are not.
1858 // The main use of this function is to allow such cases to be detected
1859 // (IsSeekable() is implemented as wxGetFileKind() == wxFILE_KIND_DISK).
1861 // This is important for the archive streams, which benefit greatly from
1862 // being able to seek on a stream, but which will produce corrupt archives
1863 // if they unknowingly seek on a non-seekable stream.
1865 // wxFILE_KIND_DISK is a good catch all return value, since other values
1866 // disable features of the archive streams. Some other value must be returned
1867 // for a file type that appears seekable but isn't.
1870 // * Pipes on Windows
1871 // * Files on VMS with a record format other than StreamLF
1873 wxFileKind
wxGetFileKind(int fd
)
1875 #if defined __WXMSW__ && !defined __WXWINCE__ && defined wxGetOSFHandle
1876 switch (::GetFileType(wxGetOSFHandle(fd
)) & ~FILE_TYPE_REMOTE
)
1878 case FILE_TYPE_CHAR
:
1879 return wxFILE_KIND_TERMINAL
;
1880 case FILE_TYPE_DISK
:
1881 return wxFILE_KIND_DISK
;
1882 case FILE_TYPE_PIPE
:
1883 return wxFILE_KIND_PIPE
;
1886 return wxFILE_KIND_UNKNOWN
;
1888 #elif defined(__UNIX__)
1890 return wxFILE_KIND_TERMINAL
;
1895 if (S_ISFIFO(st
.st_mode
))
1896 return wxFILE_KIND_PIPE
;
1897 if (!S_ISREG(st
.st_mode
))
1898 return wxFILE_KIND_UNKNOWN
;
1900 #if defined(__VMS__)
1901 if (st
.st_fab_rfm
!= FAB$C_STMLF
)
1902 return wxFILE_KIND_UNKNOWN
;
1905 return wxFILE_KIND_DISK
;
1908 #define wxFILEKIND_STUB
1910 return wxFILE_KIND_DISK
;
1914 wxFileKind
wxGetFileKind(FILE *fp
)
1916 // Note: The watcom rtl dll doesn't have fileno (the static lib does).
1917 // Should be fixed in version 1.4.
1918 #if defined(wxFILEKIND_STUB) || wxONLY_WATCOM_EARLIER_THAN(1,4)
1920 return wxFILE_KIND_DISK
;
1921 #elif defined(__WINDOWS__) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
1922 return fp
? wxGetFileKind(_fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1924 return fp
? wxGetFileKind(fileno(fp
)) : wxFILE_KIND_UNKNOWN
;
1929 //------------------------------------------------------------------------
1930 // wild character routines
1931 //------------------------------------------------------------------------
1933 bool wxIsWild( const wxString
& pattern
)
1935 wxString tmp
= pattern
;
1936 wxChar
*pat
= WXSTRINGCAST(tmp
);
1941 case wxT('?'): case wxT('*'): case wxT('['): case wxT('{'):
1952 * Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
1954 * The match procedure is public domain code (from ircII's reg.c)
1955 * but modified to suit our tastes (RN: No "%" syntax I guess)
1958 bool wxMatchWild( const wxString
& pat
, const wxString
& text
, bool dot_special
)
1962 /* Match if both are empty. */
1966 const wxChar
*m
= pat
.c_str(),
1974 if (dot_special
&& (*n
== wxT('.')))
1976 /* Never match so that hidden Unix files
1977 * are never found. */
1990 else if (*m
== wxT('?'))
1998 if (*m
== wxT('\\'))
2001 /* Quoting "nothing" is a bad thing */
2008 * If we are out of both strings or we just
2009 * saw a wildcard, then we can say we have a
2020 * We could check for *n == NULL at this point, but
2021 * since it's more common to have a character there,
2022 * check to see if they match first (m and n) and
2023 * then if they don't match, THEN we can check for
2039 * If there are no more characters in the
2040 * string, but we still need to find another
2041 * character (*m != NULL), then it will be
2042 * impossible to match it
2061 #pragma warning(default:4706) // assignment within conditional expression