How can I read keyboard without stopping

Ronald G Minnich rminnich at super.ORG
Sat Sep 3 01:06:19 AEST 1988


In article <13333 at mimsy.UUCP> chris at 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. 



More information about the Comp.unix.wizards mailing list