msvcrt: Set errno when close() is called on already closed fd.

Based on a patch by Olly Betts.

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-28 19:48:33 +01:00 committed by Alexandre Julliard
parent 53bab55d30
commit 67926ec8c3
2 changed files with 7 additions and 1 deletions

View File

@ -1051,7 +1051,7 @@ int CDECL MSVCRT__close(int fd)
if (fd == MSVCRT_NO_CONSOLE_FD) {
*MSVCRT__errno() = MSVCRT_EBADF;
ret = -1;
} else if (!(info->wxflag & WX_OPEN)) {
} else if (!MSVCRT_CHECK_PMT_ERR(info->wxflag & WX_OPEN, MSVCRT_EBADF)) {
ret = -1;
} else if (fd == MSVCRT_STDOUT_FILENO &&
info->handle == get_ioinfo_nolock(MSVCRT_STDERR_FILENO)->handle) {

View File

@ -2466,6 +2466,12 @@ static void test_close(void)
ok(!GetHandleInformation(h, &flags), "GetHandleInformation succeeded\n");
ok(close(fd2), "close(fd2) succeeded\n");
/* test close on already closed fd */
errno = 0xdeadbeef;
ret1 = close(fd1);
ok(ret1 == -1, "close(fd1) succeeded\n");
ok(errno == 9, "errno = %d\n", errno);
/* test close on stdout and stderr that use the same handle */
h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);