msvcrt: Fix close() behaviour on "no console" file descriptors.

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-15 09:47:29 +01:00 committed by Alexandre Julliard
parent 31bf13e92b
commit 677301a29c
2 changed files with 21 additions and 1 deletions

View File

@ -1047,7 +1047,11 @@ int CDECL MSVCRT__close(int fd)
int ret;
TRACE(":fd (%d) handle (%p)\n", fd, info->handle);
if (!(info->wxflag & WX_OPEN)) {
if (fd == MSVCRT_NO_CONSOLE_FD) {
*MSVCRT__errno() = MSVCRT_EBADF;
ret = -1;
} else if (!(info->wxflag & WX_OPEN)) {
ret = -1;
} else if (fd == MSVCRT_STDOUT_FILENO &&
info->handle == get_ioinfo_nolock(MSVCRT_STDERR_FILENO)->handle) {

View File

@ -1527,6 +1527,7 @@ static void test_invalid_stdin_child( void )
{
HANDLE handle;
ioinfo *info;
int ret;
errno = 0xdeadbeef;
handle = (HANDLE)_get_osfhandle(STDIN_FILENO);
@ -1538,6 +1539,21 @@ static void test_invalid_stdin_child( void )
ok(info->wxflag == 0xc1, "info->wxflag = %x\n", info->wxflag);
ok(stdin->_file == -2, "stdin->_file = %d\n", stdin->_file);
errno = 0xdeadbeef;
ret = fclose(stdin);
ok(ret == -1, "fclose(stdin) returned %d\n", ret);
ok(errno == EBADF, "errno = %d\n", errno);
errno = 0xdeadbeef;
ret = close(-2);
ok(ret == -1, "close(-2) returned %d\n", ret);
ok(errno == EBADF, "errno = %d\n", errno);
errno = 0xdeadbeef;
ret = close(STDIN_FILENO);
ok(ret==-1 || !ret, "close(STDIN_FILENO) returned %d\n", ret);
ok((ret==-1 && errno==EBADF) || (!ret && errno==0xdeadbeef), "errno = %d\n", errno);
}
static void test_invalid_stdin( const char* selfname )