4.2BSD _filbuf() question

Robert Elz kre at mulga.SUN
Tue Jan 24 12:20:30 AEST 1984


>  the documentation for the cat command reads:
>  
>  	"if the argument `-' is encountered, cat reads from the
>  	 standard input file"
>  
>  (ok, thats not from the 4.2 manual - i hope it's the same!)

It is (approximately) that in the 4.2 manual.

>  
>  this implies to me that
>  	cat - a - b - c > d
>  should read the standard input three times allowing me to enter titles.

It does just that, it reads standard input 3 times, just that
the change to _filbuf has made reads to stdin return EOF after
one EOF has been encountered, until that condition is explicitly
reset.

Whether that is the right thing for _filbuf to do is the point
under debate.  My thoughts are given by the following example ...

What does
	cat - a - b - c > d < e
produce in file 'd'?   (I don't care what system that you run this on).

Then ask yourself:  Why should it matter whether or not I made
'e' by  "cp file e" or "mknod e c maj min"  (fill in major & minor
from your own system for some terminal device, or mag tape, or ...).

The whole idea of device independant i/o is to provide similar
(at least) operation, whatever kind of beast is connected
to the file descriptor.

The change to _filbuf is a bug fix, and its immaterial how
long the bug had been there, and immaterial who or what
looks on this bug as a "feature", and exploits it for all its worth.

>  
>  i'd say it's cat's fault for treating `-' as a special case rather
>  than opening and closing the tty like it would any other file.
>  

If that's what you really want cat to do (that is, read your terminal
several times) then using "/dev/tty" will do it quite nicely.  However, of
course, "-" does not mean your tty, it means standard input, which
is not the same thing at all.

Robert Elz,  Melbourne Uni Comp Sci,		decvax!mulga!kre



More information about the Comp.unix.wizards mailing list