]> git.saurik.com Git - wxWidgets.git/commitdiff
Workaround for BCC 5.5/5.5.1 _wopen bug.
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 9 Nov 2006 22:45:19 +0000 (22:45 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 9 Nov 2006 22:45:19 +0000 (22:45 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43248 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/filefn.h
src/common/filefn.cpp

index 8bb24e01e762c12061abe6fff3e714e2997339fa..4f539ab1761be50bbe984eff53fae058912b5c36 100644 (file)
@@ -282,7 +282,12 @@ enum wxFileKind
             #endif
         #else // !wxUSE_UNICODE_MSLU
             #ifdef __BORLANDC__
-                #define   wxOpen       _wopen
+                #if __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
+                    WXDLLIMPEXP_BASE int wxOpen(const wxChar *pathname,
+                                                int flags, mode_t mode);
+                #else
+                    #define   wxOpen       _wopen
+                #endif
                 #define   wxAccess     _waccess
                 #define   wxMkDir      _mkdir
                 #define   wxRmDir      _rmdir
index 8a8b921abf5ad0d2461b3a9fe855cb22474c9dff..aeb116b6c458e0d9c2de39c81ef0cb037afe5301 100644 (file)
@@ -152,6 +152,44 @@ WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode )
 
 #endif // wxNEED_WX_UNISTD_H
 
+#if wxUSE_UNICODE && defined __BORLANDC__ \
+    && __BORLANDC__ >= 0x550 && __BORLANDC__ <= 0x551
+
+// BCC 5.5 and 5.5.1 have a bug in _wopen where files are created read only
+// regardless of the mode parameter. This hack works around the problem by
+// setting the mode with _wchmod.
+// 
+int wxOpen(const wchar_t *pathname, int flags, mode_t mode)
+{
+    int moreflags = 0;
+
+    // we only want to fix the mode when the file is actually created, so
+    // when creating first try doing it O_EXCL so we can tell if the file
+    // was already there.
+    if ((flags & O_CREAT) && !(flags & O_EXCL) && (mode & wxS_IWUSR) != 0)
+        moreflags = O_EXCL;
+
+    int fd = _wopen(pathname, flags | moreflags, mode);
+
+    // the file was actually created and needs fixing
+    if (fd != -1 && (flags & O_CREAT) != 0 && (mode & wxS_IWUSR) != 0)
+    {
+        close(fd);
+        _wchmod(pathname, mode);
+        fd = _wopen(pathname, flags & ~(O_EXCL | O_CREAT));
+    }
+    // the open failed, but it may have been because the added O_EXCL stopped
+    // the opening of an existing file, so try again without.
+    else if (fd == -1 && moreflags != 0)
+    {
+        fd = _wopen(pathname, flags & ~O_CREAT);
+    }
+
+    return fd;
+}
+
+#endif
+
 // ----------------------------------------------------------------------------
 // wxPathList
 // ----------------------------------------------------------------------------