diff options
Diffstat (limited to 'com32/libutil/get_key.c')
-rw-r--r-- | com32/libutil/get_key.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/com32/libutil/get_key.c b/com32/libutil/get_key.c index 0239d23b..e2437612 100644 --- a/com32/libutil/get_key.c +++ b/com32/libutil/get_key.c @@ -36,6 +36,8 @@ #include <stdio.h> #include <string.h> +#include <errno.h> +#include <unistd.h> #include <getkey.h> struct keycode { @@ -110,16 +112,24 @@ static const struct keycode keycodes[] = { int get_key(FILE *f) { unsigned char buffer[MAXLEN]; - int nc, ch, i; + int nc, i, rv; const struct keycode *kc; int another; + unsigned char ch; nc = 0; do { - ch = getc(f); - - if ( ch == EOF ) + rv = read(fileno(f), &ch, 1); + if ( rv == 0 ) return EOF; + else if ( rv == -1 && errno == EAGAIN ) { + if ( nc ) + return buffer[0]; /* timeout */ + else { + another = 1; + continue; + } + } buffer[nc++] = ch; @@ -128,7 +138,6 @@ int get_key(FILE *f) if ( nc == kc->seqlen && !memcmp(buffer, kc->seq, nc) ) return kc->code; else if ( nc < kc->seqlen && !memcmp(buffer, kc->seq, nc) ) { - another = 1; break; } } |