From: Piotr Caban Subject: [PATCH] msvcrt: Don't report error in fclose on already closed stream Message-Id: <640e0caa-6d75-f20d-ae52-df0f781785c4@codeweavers.com> Date: Thu, 30 Nov 2017 20:28:30 +0100 For bug #44091. Signed-off-by: Piotr Caban --- dlls/msvcrt/file.c | 6 ++++++ dlls/msvcrt/tests/file.c | 3 +++ 2 files changed, 9 insertions(+) diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 116a9bd34a..43c3fc44c4 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -3627,6 +3627,12 @@ int CDECL MSVCRT__fclose_nolock(MSVCRT_FILE* file) { int r, flag; + if(!(file->_flag & (MSVCRT__IOREAD | MSVCRT__IOWRT | MSVCRT__IORW))) + { + file->_flag = 0; + return MSVCRT_EOF; + } + flag = file->_flag; MSVCRT_free(file->_tmpfname); file->_tmpfname = NULL; diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index d4d63f271c..136ee1563e 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -1742,10 +1742,13 @@ static void test_fopen_fclose_fcloseall( void ) ok(ret == 0, "The file '%s' was not closed\n", fname2); ret = fclose(stream3); ok(ret == 0, "The file '%s' was not closed\n", fname3); + errno = 0xdeadbeef; ret = fclose(stream2); ok(ret == EOF, "Closing file '%s' returned %d\n", fname2, ret); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); ret = fclose(stream3); ok(ret == EOF, "Closing file '%s' returned %d\n", fname3, ret); + ok(errno == 0xdeadbeef, "errno = %d\n", errno); /* testing fcloseall() */ numclosed = _fcloseall();