diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 116a9bd34a2..43c3fc44c43 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 d4d63f271c3..136ee1563e6 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();