--- gforth/engine/io.c 2008/11/01 22:19:30 1.34 +++ gforth/engine/io.c 2009/06/13 10:22:24 1.35 @@ -622,6 +622,7 @@ long key_avail (FILE * stream) int tty = fileno (stream); fd_set selin; static struct timeval now = { 0 , 0 }; + int chars_avail; setvbuf(stream, NULL, _IONBF, 0); if(!terminal_prepped && stream == stdin) @@ -629,7 +630,8 @@ long key_avail (FILE * stream) FD_ZERO(&selin); FD_SET(tty, &selin); - return select(1, &selin, NULL, NULL, &now); + chars_avail = select(1, &selin, NULL, NULL, &now); + return (chars_avail == -1) ? 0 : chars_avail; } /* Get a key from the buffer of characters to be read.