]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/filefn.cpp
[ 1577675 ] Fix for GTK warnings in wxNotebook::DoRemovePage
[wxWidgets.git] / src / common / filefn.cpp
index 6fe03ab10a07a011717cc88da89ca0c4abe015b7..df91e1cb4e3f9a4417237f0e9af09cdefb0f7bf9 100644 (file)
@@ -907,6 +907,8 @@ wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname )
     return wxMacCFStringHolder(cfMutableString).AsString() ;
 }
 
+#ifndef __LP64__
+
 wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
 {
     FSRef fsRef ;
@@ -924,6 +926,7 @@ void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec )
     wxMacPathToFSRef( path , &fsRef ) ;
     err = FSRefMakeFSSpec( &fsRef , spec ) ;
 }
+#endif
 
 #endif // __WXMAC__
 
@@ -1759,6 +1762,82 @@ int WXDLLEXPORT wxParseCommonDialogsFilter(const wxString& filterStr,
     return filters.GetCount();
 }
 
+#if defined( __WINDOWS__ )
+bool wxCheckGenericPermission(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();
+    bool isdir = wxDirExists(path);
+    if (isdir && (ver == wxWinVersion_95 || ver == wxWinVersion_98 || ver == wxWinVersion_ME))
+    {
+        // 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 ?
+        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;
+    }
+}
+#endif
+
+bool wxIsWritable(const wxString &path)
+{
+#if defined( __UNIX__ )
+    // access() will take in count also symbolic links
+    return access(wxConvFile.cWX2MB(path), W_OK) == 0;
+#elif defined( __WINDOWS__ )
+    return wxCheckGenericPermission(path, GENERIC_WRITE);
+#else
+    wxUnusedVar(path);
+    // TODO
+    return false;
+#endif
+}
+
+bool wxIsReadable(const wxString &path)
+{
+#if defined( __UNIX__ )
+    // access() will take in count also symbolic links
+    return access(wxConvFile.cWX2MB(path), R_OK) == 0;
+#elif defined( __WINDOWS__ )
+    return wxCheckGenericPermission(path, GENERIC_READ);
+#else
+    wxUnusedVar(path);
+    // TODO
+    return false;
+#endif
+}
+
+bool wxIsExecutable(const wxString &path)
+{
+#if defined( __UNIX__ )
+    // access() will take in count also symbolic links
+    return access(wxConvFile.cWX2MB(path), X_OK) == 0;
+#elif defined( __WINDOWS__ )
+   return wxCheckGenericPermission(path, GENERIC_EXECUTE);
+#else
+    wxUnusedVar(path);
+    // TODO
+    return false;
+#endif
+}
+
 
 //------------------------------------------------------------------------
 // wild character routines