How to flush tty input (was Re: Problems with DIGIBOARD PC/4)
Guy Harris
guy at auspex.auspex.com
Sun Aug 19 08:02:05 AEST 1990
(Generic UNIX issue, not Xenix-specific)
>On a related topic, is there anyway to flush typeahead in Xenix?? I am
>using the Xenix equivalent of cbreak() (by setting various flags with
>ioctl()). fflush(stdin) doesn't seem to work, although it doesn't return
>an error code.
The term "flush" has, unfortunately, (at least) a couple of meanings.
(We shall ignore those such as "a hand of cards of the same suit", for
instance. :-))
It's used to mean "taking all buffered output on an output stream -
i.e., output that's been buffered up but not written to the file or
device - and writing it to the file or device".
It's also used to mean "taking all buffered input on an input stream and
throwing it away".
The first of those two meanings is the meaning of "flush" in "fflush".
*Some* C implementations will give it the second meaning in some sense
(S5R3 and some or all earlier S5 releases, I think), but others don't
(BSD). The ANSI C spec doesn't specify that, and older C language
"specifications" didn't either.
In addition, in the S5R3 implementation (and probably others that use it
to throw away input), it only throws away input that the C buffered I/O
routines (sometimes called the "standard I/O library") have buffered,
*NOT* input that, say, a device driver has buffered.
To throw away input that the terminal driver has buffered, you can, in
newer UNIXes, do:
ioctl(fd, TCFLSH, 0)
where "fd" is the file descriptor for the terminal. In this case, you
can do either "fileno(stdin)", or just 0 (which is almost certainly the
result of "fileno(stdin)", although if you work hard enough I think you
can make it non-zero - you probably haven't had any reason to do that,
though).
In older UNIXes, you may be able to use the TIOCFLUSH "ioctl", or may
have to do a TIOCGETP "ioctl" followed by a TIOCSETP "ioctl" with the
state from TIOCGETP. If your Xenix is other than a creaky old one, it
should have TCFLSH, though.
More information about the Comp.unix.questions
mailing list