--- gforth/engine/io.c 2009/12/31 15:32:36 1.39 +++ gforth/engine/io.c 2012/04/06 16:34:07 1.43 @@ -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 @@ -447,8 +448,6 @@ void deprep_terminal () #define VTIME VEOL #endif -#include - void prep_terminal () { int tty = fileno (stdin); @@ -474,9 +473,6 @@ void prep_terminal () return; /* added by MdG */ } /* added by MdG */ - setlocale(LC_ALL, ""); - setlocale(LC_NUMERIC, "C"); - /* Try to keep this function from being INTerrupted. We can do it on POSIX and systems with BSD-like signal handling. */ #if defined (HAVE_POSIX_SIGNALS) @@ -668,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)) @@ -678,9 +673,14 @@ 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); + } if (chars_avail > 0) { /* getc won't block */ int c = getc(stream);