[1/3] cmd: Avoid reading char by char from console (try 2)
Frédéric Delanoy
frederic.delanoy at gmail.com
Wed Sep 28 06:08:29 CDT 2011
2011/9/28 Alexandre Julliard <julliard at winehq.org>:
> Frédéric Delanoy <frederic.delanoy at 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
More information about the wine-devel
mailing list