4.3 curses - how to discard "premature" input?
Karl Heuer
karl at haddock.ima.isc.com
Wed Feb 22 06:41:55 AEST 1989
In article <1047 at auspex.UUCP> guy at auspex.UUCP (Guy Harris) writes:
>[fflush(stdin) doesn't work in 4.3BSD or ANSI C, and in any case doesn't
>touch the characters buffered at the driver level.]
Since there is no standard way to do this, I created my own interface (named
`clrbfi', after the TOPS-10 ttcall with the same functionality) which serves
as a portable wrapper around a non-portable operation. The enclosed code
should work on BSD, USG, and V8 systems. I'd like to include the conditional
code for MSDOS, too, but I don't know how to do it there. (Suggestions by
e-mail, please.)
Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint
-------- cut here --------
/*
* Clear input buffer on terminal. Result is 0 if successful, else -1 (e.g.
* if the specified descriptor or stream is not a tty).
*/
#if defined(_S_USG)
#include <sys/termio.h>
#define ioarg struct termio
#define GET TCGETA
#define SET TCSETAF
#else
#include <sgtty.h>
#define ioarg struct sgttyb
#define GET TIOCGETP
#define SET TIOCSETP
#endif
extern int ioctl();
int clrbfi(f) int f; {
ioarg io;
return ((ioctl(f, GET, &io) >= 0 && ioctl(f, SET, &io) >= 0) ? 0 : -1);
}
#include <stdio.h>
int fclrbfi(fp) FILE *fp; {
fp->_cnt = 0;
return (clrbfi(fileno(fp)));
}
More information about the Comp.lang.c
mailing list