From 6f8f063b90253b8aa44c1148335e43849517a7ff Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 5 Aug 2012 13:01:33 +0200 Subject: [PATCH] Simplify win32 read_stdin(). Still untested. --- command.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/command.c b/command.c index 3e6fda43f1..91b5288b0b 100644 --- a/command.c +++ b/command.c @@ -248,25 +248,16 @@ static size_t read_stdin(char *buf, size_t size) // Check first if we're a pipe // (not console). DWORD avail = 0; - BOOL ret = PeekNamedPipe(hnd, NULL, 0, NULL, &avail, NULL); - if (!ret) // If not a pipe, check if we're running in a console. + // If not a pipe, check if we're running in a console. + if (!PeekNamedPipe(hnd, NULL, 0, NULL, &avail, NULL)) { - DWORD mode = 0; + DWORD mode; if (!GetConsoleMode(hnd, &mode)) return 0; - INPUT_RECORD rec = {0}; - DWORD has_read = 0; - - do - { - has_read = 0; - PeekConsoleInput(hnd, &rec, 1, &has_read); - } while (has_read && rec.EventType != KEY_EVENT); - - if (rec.EventType == KEY_EVENT) - avail = size; + if (!GetNumberOfConsoleInputEvents(hnd, &avail)) + return 0; } if (!avail)