Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.unix.programmer Subject: Re: Non-destructive read of keyboard buffer Message-ID: <8284@auspex.auspex.com> Date: 9 Jun 91 21:15:06 GMT Article-I.D.: auspex.8284 References: <22368@duke.cs.duke.edu> Organization: Auspex Systems, Santa Clara Lines: 20 > Hi, I am trying to find out if a keyboard buffer is empty but not reading > it because I don't want to get stuck if there isn't any buffered. > (on ATT SVR3) > > Is there a 'standard' way on unix to do this ? > >You can use select(2) under BSD, Unfortunately, he's not *using* BSD; he's using System V Release 3, as he said. No, SVR3 doesn't necessarily have "select()", nor the FIONBIO "ioctl", nor EWOULDBLOCK. Answer: it does have non-blocking I/O on ttys; check out the F_GETFL and F_SETFL "fcntl" calls. WARNING: unlike various things in BSD, non-streams ttys return 0, not -1, if no data is available to be read and they're in non-blocking mode. The program must make absolutely positively sure that it doesn't leave the terminal in non-blocking mode; otherwise, if it exits and leaves the terminal in that mode, the shell may see a zero-byte return if the user doesn't type a command fast enough, will think that's an end-of-file, and exit.