Non-destructive read of keyboard buffer
Guy Harris
guy at auspex.auspex.com
Mon Jun 10 07:15:06 AEST 1991
> 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.
More information about the Comp.unix.programmer
mailing list