Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!decvax!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: 4.3 curses - how to discard "premature" input? Message-ID: <11820@haddock.ima.isc.com> Date: 21 Feb 89 20:41:55 GMT References: <15336@oberon.USC.EDU> <697@sactoh0.UUCP> <1047@auspex.UUCP> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Distribution: usa Organization: Interactive Systems, Boston Lines: 41 In article <1047@auspex.UUCP> guy@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@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 #define ioarg struct termio #define GET TCGETA #define SET TCSETAF #else #include #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 int fclrbfi(fp) FILE *fp; { fp->_cnt = 0; return (clrbfi(fileno(fp))); }