Fixes https://bugs.winehq.org/show_bug.cgi?id=44550
gets() and getws() should return NULL when STDIN is closed and the input buffer is empty.
Tested on Ubuntu 17.10.
Signed-off-by: James Woodcock james_woodcock@yahoo.co.uk --- dlls/msvcrt/file.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 7022e48b19..f36780ba97 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -4719,6 +4719,14 @@ char * CDECL MSVCRT_gets(char *buf) if(cc != '\r') *buf++ = (char)cc; } + + if ((cc == MSVCRT_EOF) && (buf_start == buf)) /* If nothing read, return 0*/ + { + TRACE(":nothing read\n"); + MSVCRT__unlock_file(MSVCRT_stdin); + return NULL; + } + *buf = '\0';
TRACE("got '%s'\n", buf_start); @@ -4741,6 +4749,14 @@ MSVCRT_wchar_t* CDECL MSVCRT__getws(MSVCRT_wchar_t* buf) if (cc != '\r') *buf++ = (MSVCRT_wchar_t)cc; } + + if ((cc == MSVCRT_WEOF) && (ws == buf)) /* If nothing read, return 0*/ + { + TRACE(":nothing read\n"); + MSVCRT__unlock_file(MSVCRT_stdin); + return NULL; + } + *buf = '\0';
TRACE("got %s\n", debugstr_w(ws));