Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!nrl-cmf!cmcl2!rutgers!ucsd!ucsdhub!esosun!seismo!uunet!super!rminnich From: rminnich@super.ORG (Ronald G Minnich) Newsgroups: comp.unix.wizards Subject: Re: How can I read keyboard without stopping Keywords: curses keyboard Message-ID: <690@super.ORG> Date: 2 Sep 88 15:06:19 GMT References: <813@ms3.UUCP> <1246@mcgill-vision.UUCP> <669@super.ORG> <679@super.ORG> <13333@mimsy.UUCP> Sender: uucp@super.ORG Reply-To: rminnich@metropolis.UUCP (Ronald G Minnich) Organization: Supercomputing Research Center, Lanham, MD Lines: 34 In article <13333@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: >>I.e. for some arbitrary file descriptor, you do a stat, >>and that stat indicates 0 bytes to read. OK, are you >>at EOF, or are you at a lull in the data? Last time i looked >This paragraph seems hopelessly confused. stat says how big the file >is, and is completely orthogonal to your current seek offset. And I >thought we were talking about tty devices, not pipes. Well, it is confused. Sorry. Let me try again... It turns out that a portable way to do the equivalent of FIONREAD on a pipe is to use stat. The size field will tell you how much data is in the pipe. You then read that much data, and you don't get blocked. Handy, esp. for the many systems that didn't support FIONREAD (this was five years ago). The fact that that worked is what led me to expect some similar operation on tty lines. No such luck. I was not talking about tty devices, rather peter da silva's original comment questioning stat's not supporting the size field for ttys. That comment got me to thinking about stat()s lack of generality, since i had been burned by it once. I think that he was making the same point. >On regular files, you are at EOF if your current seek offset (available >via lseek()) matches the size returned via fstat(). Tty devices do not Only if someone else is not writing? If you are reading a regular file, and someone else is writing, then there are times when your current seek offset will match the returned size. You are still not at eof, as someone else has the file open. More data can come along. This is 'nothing available to read, but you are not at eof'. I.e. tail -f, tail never really does know when it hits eof- you, peculiar creature that you are, decide for it via ^C :-). ron P.S. Does it strike anyone as strange that stdio and level 2 have such different ideas about eof? Level 2 you can just read right through ^D; As was pointed out, it is more like an enforced one-read FNDELAY than anything else. for standard IO, one is enough; you lose it all right there. The FILE * gets closed for you.