4.2BSD _filbuf() question

dbj%rice at sri-unix.UUCP dbj%rice at sri-unix.UUCP
Sat Jan 21 11:48:30 AEST 1984


From:  Dave Johnson <dbj at rice>

    "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."

Reading standard input each time for the "-" does NOT mean "opening and
closing the tty"!  Standard input is whatever is on file descriptor 0 when
the program starts up; it is not always the terminal.  Also, if you have
done an "su" to some other user (other than root) after logging on, "cat"
will usually be unable to open the terminal since usually only the person
who actually logged on to the terminal can read from it (although it could
get at the terminal with "/dev/tty" rather than the specific terminal).

"Cat" should simply do a clearerr() on stdin after reaching the end of file
each time, so that when it needs to read stdin again for the next "-", it
won't think that it's already at end of file.

                                        Dave Johnson
                                        Dept. of Math Science
                                        Rice University
                                        dbj at rice



More information about the Comp.unix.wizards mailing list