From 023af02b0b3c0643b612183f8670807b081125f4 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 1 Jun 2013 08:00:36 +0200 Subject: [PATCH] Add routine to check for input --- hachu.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/hachu.c b/hachu.c index 478a20b..ff5cc8f 100644 --- a/hachu.c +++ b/hachu.c @@ -29,8 +29,25 @@ #ifdef WIN32 # include + int InputWaiting() + { // checks for waiting input in pipe + static int pipe, init; + static HANDLE inp; + DWORD cnt; + + if(!init) inp = GetStdHandle(STD_INPUT_HANDLE); + if(!PeekNamedPipe(inp, NULL, 0, NULL, &cnt, NULL)) return 1; + return cnt; + } #else # include +# include + int InputWaiting() + { + int cnt; + if(ioctl(0, FIONREAD, &cnt)) return 1; + return cnt; + } int GetTickCount() // with thanks to Tord { struct timeval t; gettimeofday(&t, NULL); -- 1.7.0.4