Commit 67926ec8 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

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

Based on a patch by Olly Betts. Signed-off-by: 's avatarPiotr Caban <piotr@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 53bab55d
...@@ -1051,7 +1051,7 @@ int CDECL MSVCRT__close(int fd) ...@@ -1051,7 +1051,7 @@ int CDECL MSVCRT__close(int fd)
if (fd == MSVCRT_NO_CONSOLE_FD) { if (fd == MSVCRT_NO_CONSOLE_FD) {
*MSVCRT__errno() = MSVCRT_EBADF; *MSVCRT__errno() = MSVCRT_EBADF;
ret = -1; ret = -1;
} else if (!(info->wxflag & WX_OPEN)) { } else if (!MSVCRT_CHECK_PMT_ERR(info->wxflag & WX_OPEN, MSVCRT_EBADF)) {
ret = -1; ret = -1;
} else if (fd == MSVCRT_STDOUT_FILENO && } else if (fd == MSVCRT_STDOUT_FILENO &&
info->handle == get_ioinfo_nolock(MSVCRT_STDERR_FILENO)->handle) { info->handle == get_ioinfo_nolock(MSVCRT_STDERR_FILENO)->handle) {
......
...@@ -2466,6 +2466,12 @@ static void test_close(void) ...@@ -2466,6 +2466,12 @@ static void test_close(void)
ok(!GetHandleInformation(h, &flags), "GetHandleInformation succeeded\n"); ok(!GetHandleInformation(h, &flags), "GetHandleInformation succeeded\n");
ok(close(fd2), "close(fd2) 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 */ /* test close on stdout and stderr that use the same handle */
h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE, h = CreateFileA("fdopen.tst", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL); FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment