Xref: utzoo comp.unix.wizards:12218 comp.bugs.sys5:678 Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!agate!labrea!rutgers!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!uw-june!ka From: ka@june.cs.washington.edu (Kenneth Almquist) Newsgroups: comp.unix.wizards,comp.bugs.sys5 Subject: Re: empty() for USG UNIX ? Summary: No such thing Message-ID: <6373@june.cs.washington.edu> Date: 9 Nov 88 01:28:56 GMT References: <292@rna.UUCP> Organization: U of Washington, Computer Science, Seattle Lines: 29 Dan Ts'o asks for a System V routine to test whether data is available to be read on a file descriptor referring to a slow device (such as a tty). I doubt that such a routine can be written. Depending on what you are doing, you may be able to use FNDELAY mode to get the same effect. Code like: ioctl(fd, FIONREAD, (char *)&nchars); if (nchars) { count = read(fd, buf, sizeof(buf)); Code to process input. } else { Do something else. } becomes: fcntl(fd, F_SETFL, FNDELAY); if ((count = read(fd, buf, sizeof(buf))) != 0) { Code to process input. } else { Do something else. } These two pieces of code are approximately equivalent, but the former contains a race condition. (The fact that characters are available to be read when the FIONREAD ioctl is performed doesn't mean that these characters will still be around by the time the code gets around to performing the read.) So the latter version of the code is preferable on systems that support both. Kenneth Almquist