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
This commit is contained in:
Michael Wetherell
2006-11-09 22:45:19 +00:00
parent a04be1e3e8
commit 311b04034e
2 changed files with 44 additions and 1 deletions

View 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

View 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
// ----------------------------------------------------------------------------