From 2f5e5f3d29aa18fcddff0d734227a85a46347175 Mon Sep 17 00:00:00 2001 From: Adam Gundy Date: Sun, 30 Mar 2003 03:06:30 +0000 Subject: [PATCH] MSVCRT_fclose() mustn't use the _flag field from the file structure after _close() has been called. When _open_osfhandle() is used by MFC's CStdioFile, it expects write access even though it doesn't set the necessary flag bit. --- dlls/msvcrt/file.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index dbda46d615f..86548a607e4 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -1124,10 +1124,13 @@ int _wcreat(const MSVCRT_wchar_t *path, int flags) */ int _open_osfhandle(long hand, int flags) { - /* _O_RDONLY (0) always matches, so set the read flag*/ + /* _O_RDONLY (0) always matches, so set the read flag + * MFC's CStdioFile clears O_RDONLY (0)! if it wants to write to the + * file, so set the write flag + */ /* FIXME: handle more flags */ - int fd= msvcrt_alloc_fd((HANDLE)hand,flags|MSVCRT__IOREAD); - TRACE(":handle (%ld) fd (%d) flags 0x%08x\n",hand,fd, flags |MSVCRT__IOREAD); + int fd= msvcrt_alloc_fd((HANDLE)hand,flags|MSVCRT__IOREAD|MSVCRT__IOWRT); + TRACE(":handle (%ld) fd (%d) flags 0x%08x\n",hand,fd, flags |MSVCRT__IOREAD|MSVCRT__IOWRT); return fd; } @@ -1556,9 +1559,11 @@ void MSVCRT_clearerr(MSVCRT_FILE* file) */ int MSVCRT_fclose(MSVCRT_FILE* file) { - int r; + int r, flag; + + flag = file->_flag; r=_close(file->_file); - return ((r==MSVCRT_EOF) || (file->_flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0); + return ((r==MSVCRT_EOF) || (flag & MSVCRT__IOERR) ? MSVCRT_EOF : 0); } /*********************************************************************