X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8b6a1b1cdf05ed38d2953145b438fb46fe13248..a97d569cbbf90ba8bb293214055c3a8c19d447b5:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 435ff24df6..bc6c67ae79 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -115,13 +115,17 @@ const int wxInvalidOffset = -1; // macros // ---------------------------------------------------------------------------- -// we need to translate Mac filenames before passing them to OS functions +// translate the filenames before passing them to OS functions #define OS_FILENAME(s) (s.fn_str()) // ============================================================================ // implementation // ============================================================================ +// ---------------------------------------------------------------------------- +// wrappers around standard POSIX functions +// ---------------------------------------------------------------------------- + #ifdef wxNEED_WX_UNISTD_H WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) @@ -129,6 +133,11 @@ WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf ) return stat( wxConvFile.cWX2MB( file_name ), buf ); } +WXDLLEXPORT int wxLstat( const wxChar *file_name, wxStructStat *buf ) +{ + return lstat( wxConvFile.cWX2MB( file_name ), buf ); +} + WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode ) { return access( wxConvFile.cWX2MB( pathname ), mode ); @@ -139,8 +148,7 @@ WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode ) return open( wxConvFile.cWX2MB( pathname ), flags, mode ); } -#endif - // wxNEED_WX_UNISTD_H +#endif // wxNEED_WX_UNISTD_H // ---------------------------------------------------------------------------- // wxPathList @@ -907,6 +915,8 @@ wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) return wxMacCFStringHolder(cfMutableString).AsString() ; } +#ifndef __LP64__ + wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) { FSRef fsRef ; @@ -924,6 +934,7 @@ void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec ) wxMacPathToFSRef( path , &fsRef ) ; err = FSRefMakeFSSpec( &fsRef , spec ) ; } +#endif #endif // __WXMAC__ @@ -1229,7 +1240,7 @@ bool wxDirExists(const wxChar *pszPathName) #if defined(__WINDOWS__) || defined(__OS2__) // Windows fails to find directory named "c:\dir\" even if "c:\dir" exists, // so remove all trailing backslashes from the path - but don't do this for - // the pathes "d:\" (which are different from "d:") nor for just "\" + // the paths "d:\" (which are different from "d:") nor for just "\" while ( wxEndsWithPathSeparator(strPath) ) { size_t len = strPath.length(); @@ -1277,9 +1288,8 @@ bool wxDirExists(const wxChar *pszPathName) // Get a temporary filename, opening and closing the file. wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) { -#if wxUSE_FILE - wxString filename = wxFileName::CreateTempFileName(prefix); - if ( filename.empty() ) + wxString filename; + if ( !wxGetTempFileName(prefix, filename) ) return NULL; if ( buf ) @@ -1288,19 +1298,20 @@ wxChar *wxGetTempFileName(const wxString& prefix, wxChar *buf) buf = MYcopystring(filename); return buf; -#else - wxUnusedVar(prefix); - wxUnusedVar(buf); - // wxFileName::CreateTempFileName needs wxFile class enabled - return NULL; -#endif } bool wxGetTempFileName(const wxString& prefix, wxString& buf) { - buf = wxGetTempFileName(prefix); +#if wxUSE_FILE + buf = wxFileName::CreateTempFileName(prefix); return !buf.empty(); +#else // !wxUSE_FILE + wxUnusedVar(prefix); + wxUnusedVar(buf); + + return false; +#endif // wxUSE_FILE/!wxUSE_FILE } // Get first file name matching given wild card. @@ -1760,46 +1771,43 @@ int WXDLLEXPORT wxParseCommonDialogsFilter(const wxString& filterStr, } #if defined( __WINDOWS__ ) -bool wxCheckGenericPermission(const wxString &path, DWORD access) +static bool wxCheckWin32Permission(const wxString& path, DWORD access) { // quoting the MSDN: "To obtain a handle to a directory, call the - // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag" - wxWinVersion ver = wxGetWinVersion(); + // CreateFile function with the FILE_FLAG_BACKUP_SEMANTICS flag", but this + // doesn't work under Win9x/ME but then it's not needed there anyhow bool isdir = wxDirExists(path); - if (isdir && (ver == wxWinVersion_95 || ver == wxWinVersion_98 || ver == wxWinVersion_ME)) + if ( isdir && wxGetOsVersion() == wxOS_WINDOWS_9X ) { - // however Win95/98/ME do not support FILE_FLAG_BACKUP_SEMANTICS... - if (access == GENERIC_READ) - { - WIN32_FILE_ATTRIBUTE_DATA data; - if (GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &data) == 0) - return false; // cannot query attributes - return (data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0; - } - - // FIXME: is it true that directories are always writable & executable on Win9X family ? + // FAT directories always allow all access, even if they have the + // readonly flag set return true; } - else - { - HANDLE h = CreateFile(path.c_str(), access, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, - OPEN_EXISTING, isdir ? FILE_FLAG_BACKUP_SEMANTICS : 0, NULL); - if (h != INVALID_HANDLE_VALUE) - CloseHandle(h); - return h != INVALID_HANDLE_VALUE; - } + HANDLE h = ::CreateFile + ( + path.c_str(), + access, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + isdir ? FILE_FLAG_BACKUP_SEMANTICS : 0, + NULL + ); + if ( h != INVALID_HANDLE_VALUE ) + CloseHandle(h); + + return h != INVALID_HANDLE_VALUE; } -#endif +#endif // __WINDOWS__ bool wxIsWritable(const wxString &path) { -#if defined( __UNIX__ ) +#if defined( __UNIX__ ) || defined(__OS2__) // access() will take in count also symbolic links return access(wxConvFile.cWX2MB(path), W_OK) == 0; #elif defined( __WINDOWS__ ) - return wxCheckGenericPermission(path, GENERIC_WRITE); + return wxCheckWin32Permission(path, GENERIC_WRITE); #else wxUnusedVar(path); // TODO @@ -1809,11 +1817,11 @@ bool wxIsWritable(const wxString &path) bool wxIsReadable(const wxString &path) { -#if defined( __UNIX__ ) +#if defined( __UNIX__ ) || defined(__OS2__) // access() will take in count also symbolic links return access(wxConvFile.cWX2MB(path), R_OK) == 0; #elif defined( __WINDOWS__ ) - return wxCheckGenericPermission(path, GENERIC_READ); + return wxCheckWin32Permission(path, GENERIC_READ); #else wxUnusedVar(path); // TODO @@ -1823,11 +1831,11 @@ bool wxIsReadable(const wxString &path) bool wxIsExecutable(const wxString &path) { -#if defined( __UNIX__ ) +#if defined( __UNIX__ ) || defined(__OS2__) // access() will take in count also symbolic links return access(wxConvFile.cWX2MB(path), X_OK) == 0; #elif defined( __WINDOWS__ ) - return wxCheckGenericPermission(path, GENERIC_EXECUTE); + return wxCheckWin32Permission(path, GENERIC_EXECUTE); #else wxUnusedVar(path); // TODO