Module: wine Branch: master Commit: a7e1c22a485fb7b87e2c344b472f7e6778d5eafe URL: http://source.winehq.org/git/wine.git/?a=commit;h=a7e1c22a485fb7b87e2c344b47...
Author: Frédéric Delanoy frederic.delanoy@gmail.com Date: Wed Sep 28 14:41:20 2011 +0200
cmd: Avoid reading char by char from console.
---
programs/cmd/batch.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index c5e73c6..5007db3 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -181,13 +181,23 @@ 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; +WCHAR *WCMD_fgets (WCHAR *s, int noChars, HANDLE h) +{ + DWORD bytes, charsRead; BOOL status; WCHAR *p;
p = s; + if ((status = ReadConsoleW(h, s, noChars, &charsRead, NULL))) { + s[charsRead-2] = '\0'; /* Strip \r\n */ + return p; + } + + /* Continue only if we have no console (i.e. a file) handle */ + if (GetLastError() != ERROR_INVALID_HANDLE) + return NULL; + + /* TODO: More intelligent buffering for reading lines from files */ do { status = WCMD_ReadFile (h, s, 1, &bytes, NULL); if ((status == 0) || ((bytes == 0) && (s == p))) return NULL;