diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 44aa32ed4b4..68d4d54a265 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -2833,6 +2833,11 @@ int CDECL MSVCRT__setmode(int fd,int mode) return -1; } + if(info == &MSVCRT___badioinfo) { + *MSVCRT__errno() = MSVCRT_EBADF; + return -1; + } + if(mode == MSVCRT__O_BINARY) { info->wxflag &= ~WX_TEXT; info->exflag &= ~(EF_UTF8|EF_UTF16); diff --git a/dlls/msvcrt/tests/file.c b/dlls/msvcrt/tests/file.c index c4d8fa1364b..ba8c3e389c6 100644 --- a/dlls/msvcrt/tests/file.c +++ b/dlls/msvcrt/tests/file.c @@ -1789,6 +1789,16 @@ static void test_setmode(void) return; } + errno = 0xdeadbeef; + ret = _setmode(-2, 0); + ok(ret == -1, "_setmode returned %x, expected -1\n", ret); + ok(errno == EINVAL, "errno = %d\n", errno); + + errno = 0xdeadbeef; + ret = _setmode(-2, _O_TEXT); + ok(ret == -1, "_setmode returned %x, expected -1\n", ret); + ok(errno == EBADF, "errno = %d\n", errno); + fd = _open(name, _O_CREAT|_O_WRONLY, _S_IWRITE); ok(fd != -1, "failed to open file\n");