Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 alpha 4/15/85; site lzwi.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!ihnp4!lzwi!psc From: psc@lzwi.UUCP (Paul S. R. Chisholm) Newsgroups: net.unix-wizards,net.unix Subject: Re: unix terminal i/o Message-ID: <179@lzwi.UUCP> Date: Tue, 18-Jun-85 09:17:57 EDT Article-I.D.: lzwi.179 Posted: Tue Jun 18 09:17:57 1985 Date-Received: Wed, 19-Jun-85 04:20:11 EDT References: <452@mmintl.UUCP> Organization: AT&T-IS Enhanced Network Systems Lines: 28 Xref: watmath net.unix-wizards:13568 net.unix:4827 Summary: VMIN=VTIME=0 or fcntl(O_NDELAY) < Smokey the Bar says, "Help stamp out software pirates" [squish!] > In article <452@mmintl.UUCP>, robg@mmintl.UUCP (Robert Goldman) writes: > > I am working on a program that needs to access the terminal in a pretty raw > state. In particular, it must have some way to tell whether there are any > keys in the input buffer waiting to be read. Is there some portable unix > call that responds with this information? > Robert Goldman, MultiMate International In Unix(tm) System III and V (all releases), you can ioctl() the line to have VMIN and VTIME set to 0; a read() will only get any characters in the input queue. (Note that ioctl(fd,TCFLSH,0) will flush the input queue.) More portably, you can fcntl() the file descriptor with O_NDELAY, which avoids blocking on tty's and pipes (and fifos). If you're always going to avoid blocking, you can open() the file with O_NDELAY. Both ioctl() and fcntl() are pretty cheap to call, so it's not too expensive to go back and forth. -- Unix is a trademark of some entity within AT&T, but I don't know what it's called this week. AT&T's Bell Labs? -- -Paul S. R. Chisholm The above opinions are my own, {pegasus,vax135}!lzwi!psc not necessarily those of any {mtgzz,ihnp4}!lznv!psc telecommunications company.