msvcrt: Gets() should handle EOF on stdin gracefully.

Signed-off-by: James Woodcock <james_woodcock@yahoo.co.uk>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
James Woodcock 2018-03-06 22:16:28 -06:00 committed by Alexandre Julliard
parent 38482b326a
commit 91c72ce7de
1 changed files with 14 additions and 2 deletions

View File

@ -4719,10 +4719,16 @@ char * CDECL MSVCRT_gets(char *buf)
if(cc != '\r')
*buf++ = (char)cc;
}
MSVCRT__unlock_file(MSVCRT_stdin);
if ((cc == MSVCRT_EOF) && (buf_start == buf))
{
TRACE(":nothing read\n");
return NULL;
}
*buf = '\0';
TRACE("got '%s'\n", buf_start);
MSVCRT__unlock_file(MSVCRT_stdin);
return buf_start;
}
@ -4741,10 +4747,16 @@ MSVCRT_wchar_t* CDECL MSVCRT__getws(MSVCRT_wchar_t* buf)
if (cc != '\r')
*buf++ = (MSVCRT_wchar_t)cc;
}
MSVCRT__unlock_file(MSVCRT_stdin);
if ((cc == MSVCRT_WEOF) && (ws == buf))
{
TRACE(":nothing read\n");
return NULL;
}
*buf = '\0';
TRACE("got %s\n", debugstr_w(ws));
MSVCRT__unlock_file(MSVCRT_stdin);
return ws;
}