--- gforth/engine/io.c 2010/02/14 18:13:31 1.40 +++ gforth/engine/io.c 2012/07/22 22:24:50 1.44 @@ -1,6 +1,6 @@ /* direct key io driver - Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006,2007,2008,2009 Free Software Foundation, Inc. + Copyright (C) 1995,1996,1997,1998,1999,2002,2003,2006,2007,2008,2009,2010 Free Software Foundation, Inc. This file is part of Gforth. @@ -55,6 +55,7 @@ typedef unsigned int uint32_t; #include "io.h" #ifndef MSDOS +#include #if defined (__GNUC__) # define alloca __builtin_alloca #else @@ -663,8 +664,7 @@ int gf_ungottenc(FILE *stream) long key_avail (FILE *stream) { int tty = fileno (stream); - fd_set selin; - static struct timeval now = { 0 , 0 }; + struct pollfd fds = { tty, POLLIN, 0 }; int chars_avail; if (gf_ungottenc(stream)) @@ -673,9 +673,15 @@ long key_avail (FILE *stream) if(!terminal_prepped && stream == stdin) prep_terminal(); - FD_ZERO(&selin); - FD_SET(tty, &selin); - chars_avail = select(1, &selin, NULL, NULL, &now); +#if defined(FIONREAD) && !defined(_WIN32) + if(isatty (tty)) { + int result = ioctl (tty, FIONREAD, &chars_avail); + } else +#endif + { + chars_avail = poll(&fds, 1, 0); + } +#ifndef __ANDROID__ if (chars_avail > 0) { /* getc won't block */ int c = getc(stream); @@ -683,6 +689,7 @@ long key_avail (FILE *stream) return 0; gf_ungetc(c, stream); } +#endif return (chars_avail == -1) ? 0 : chars_avail; }