2011/9/28 Alexandre Julliard <julliard(a)winehq.org>:
Frédéric Delanoy <frederic.delanoy(a)gmail.com> writes:
@@ -181,13 +181,21 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **where, WCHAR **end) { * the LF (or CRLF) from the line. */
-WCHAR *WCMD_fgets (WCHAR *s, int noChars, HANDLE h) { - - DWORD bytes; - BOOL status; +WCHAR *WCMD_fgets (WCHAR *s, int noChars, HANDLE h) +{ + DWORD bytes, charsRead, dummy; + BOOL status, is_console_handle; WCHAR *p;
p = s; + is_console_handle = !!GetConsoleMode(h, &dummy); + if (is_console_handle) { + status = ReadConsoleW(h, s, noChars, &charsRead, NULL);
ReadConsole will fail if it's not a console, the check is redundant.
Yes, but it can fail for other reasons as well. If it really is a console handle, but ReadConsoleW fails, isn't it better to return failure early rather than trying to read from (assumed) file handle h? Frédéric