Diff for /gforth/engine/io.c between versions 1.41 and 1.45

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

Removed from v.1.41  
changed lines
  Added in v.1.45


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>