Piotr Caban : msvcrt: Set errno when close() is called on already closed fd.
Alexandre Julliard
julliard at winehq.org
Tue Nov 28 15:11:05 CST 2017
Module: wine
Branch: master
Commit: 67926ec8c344db4250f1e74a5943d0b8a536e950
URL: http://source.winehq.org/git/wine.git/?a=commit;h=67926ec8c344db4250f1e74a5943d0b8a536e950
Author: Piotr Caban <piotr at codeweavers.com>
Date: Tue Nov 28 19:48:33 2017 +0100
msvcrt: Set errno when close() is called on already closed fd.
Based on a patch by Olly Betts.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/file.c | 2 +-
dlls/msvcrt/tests/file.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index 5eaee2b..1e662e9 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -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) {
diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c
index 99ceb97..00f5e7e 100644
--- a/dlls/msvcrt/tests/file.c
+++ b/dlls/msvcrt/tests/file.c
@@ -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);
More information about the wine-cvs
mailing list