msvcrt: Don't report error in fclose on already closed stream.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2017-11-30 20:28:30 +01:00 committed by Alexandre Julliard
parent 1899eadf3e
commit 96584d858a
2 changed files with 9 additions and 0 deletions

View File

@ -3627,6 +3627,12 @@ int CDECL MSVCRT__fclose_nolock(MSVCRT_FILE* file)
{ {
int r, flag; int r, flag;
if(!(file->_flag & (MSVCRT__IOREAD | MSVCRT__IOWRT | MSVCRT__IORW)))
{
file->_flag = 0;
return MSVCRT_EOF;
}
flag = file->_flag; flag = file->_flag;
MSVCRT_free(file->_tmpfname); MSVCRT_free(file->_tmpfname);
file->_tmpfname = NULL; file->_tmpfname = NULL;

View File

@ -1742,10 +1742,13 @@ static void test_fopen_fclose_fcloseall( void )
ok(ret == 0, "The file '%s' was not closed\n", fname2); ok(ret == 0, "The file '%s' was not closed\n", fname2);
ret = fclose(stream3); ret = fclose(stream3);
ok(ret == 0, "The file '%s' was not closed\n", fname3); ok(ret == 0, "The file '%s' was not closed\n", fname3);
errno = 0xdeadbeef;
ret = fclose(stream2); ret = fclose(stream2);
ok(ret == EOF, "Closing file '%s' returned %d\n", fname2, ret); ok(ret == EOF, "Closing file '%s' returned %d\n", fname2, ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
ret = fclose(stream3); ret = fclose(stream3);
ok(ret == EOF, "Closing file '%s' returned %d\n", fname3, ret); ok(ret == EOF, "Closing file '%s' returned %d\n", fname3, ret);
ok(errno == 0xdeadbeef, "errno = %d\n", errno);
/* testing fcloseall() */ /* testing fcloseall() */
numclosed = _fcloseall(); numclosed = _fcloseall();