X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31004b74058ca584729db0b7fe889ea89d89ff14..6362d82b3ed82aa6795e4ad03160820f94c9e4d4:/src/common/filefn.cpp diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 7a8f627a55..24324f04ee 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -96,6 +96,10 @@ #define _MAXPATHLEN 1024 #endif +#ifndef INVALID_FILE_ATTRIBUTES + #define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif + // ---------------------------------------------------------------------------- // private globals // ---------------------------------------------------------------------------- @@ -316,7 +320,7 @@ wxFileExists (const wxString& filename) // it can cope with network (UNC) paths unlike them DWORD ret = ::GetFileAttributes(filename.fn_str()); - return (ret != (DWORD)-1) && !(ret & FILE_ATTRIBUTE_DIRECTORY); + return (ret != INVALID_FILE_ATTRIBUTES) && !(ret & FILE_ATTRIBUTE_DIRECTORY); #else // !__WIN32__ #ifndef S_ISREG #define S_ISREG(mode) ((mode) & S_IFREG) @@ -1339,7 +1343,7 @@ bool wxDirExists(const wxString& pathName) // stat() can't cope with network paths DWORD ret = ::GetFileAttributes(strPath.fn_str()); - return (ret != (DWORD)-1) && (ret & FILE_ATTRIBUTE_DIRECTORY); + return (ret != INVALID_FILE_ATTRIBUTES) && (ret & FILE_ATTRIBUTE_DIRECTORY); #elif defined(__OS2__) FILESTATUS3 Info = {{0}}; APIRET rc = ::DosQueryPathInfo((PSZ)(WXSTRINGCAST strPath), FIL_STANDARD, @@ -1840,12 +1844,20 @@ 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", but this // doesn't work under Win9x/ME but then it's not needed there anyhow - bool isdir = wxDirExists(path); - if ( isdir && wxGetOsVersion() == wxOS_WINDOWS_9X ) + const DWORD dwAttr = ::GetFileAttributes(path.fn_str()); + if ( dwAttr == INVALID_FILE_ATTRIBUTES ) + { + // file probably doesn't exist at all + return false; + } + + if ( wxGetOsVersion() == wxOS_WINDOWS_9X ) { // FAT directories always allow all access, even if they have the - // readonly flag set - return true; + // readonly flag set, and FAT files can only be read-only + return (dwAttr & FILE_ATTRIBUTE_DIRECTORY) || + (access != GENERIC_WRITE || + !(dwAttr & FILE_ATTRIBUTE_READONLY)); } HANDLE h = ::CreateFile @@ -1855,7 +1867,9 @@ static bool wxCheckWin32Permission(const wxString& path, DWORD access) FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, - isdir ? FILE_FLAG_BACKUP_SEMANTICS : 0, + dwAttr & FILE_ATTRIBUTE_DIRECTORY + ? FILE_FLAG_BACKUP_SEMANTICS + : 0, NULL ); if ( h != INVALID_HANDLE_VALUE )