summaryrefslogtreecommitdiff
path: root/com32/libutil/get_key.c
diff options
context:
space:
mode:
authorhpa <hpa>2004-12-20 22:28:30 +0000
committerhpa <hpa>2004-12-20 22:28:30 +0000
commit27007ae32a1244db12ba1e8e12352785075010a1 (patch)
tree39fc9205d1802525778e58db95ad853ee4678d01 /com32/libutil/get_key.c
parentf22543d9d32c3866b6d42392c2957c6c76098964 (diff)
downloadsyslinux-27007ae32a1244db12ba1e8e12352785075010a1.tar.gz
Make the raw input console non-blocking with a timeout, allows handling
the [Esc] key.
Diffstat (limited to 'com32/libutil/get_key.c')
-rw-r--r--com32/libutil/get_key.c19
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;
}
}