From 311b04034e700a4a633b47b721cd27568602a3d7 Mon Sep 17 00:00:00 2001 From: Michael Wetherell Date: Thu, 9 Nov 2006 22:45:19 +0000 Subject: [PATCH] Workaround for BCC 5.5/5.5.1 _wopen bug. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43248 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/filefn.h | 7 ++++++- src/common/filefn.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/include/wx/filefn.h b/include/wx/filefn.h index 8bb24e01e7..4f539ab176 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -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 diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 8a8b921abf..aeb116b6c4 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -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 // ---------------------------------------------------------------------------- -- 2.45.2