On Sat, Jan 21, 2023, 10:34 AM Warner Losh <imp@bsdimp.com> wrote:


On Sat, Jan 21, 2023, 8:45 AM Clem Cole <clemc@ccc.com> wrote:
Certainly fd 2 as a error output appears with Lesk's portable C library, which was included in V6 - see the last para on page 1 of his document:

"Initially you are given three file descriptors by the system: 0, 1, and 2. File 0 is the standard input; it is normally the teletype in time-sharing or input data cards in batch. File 1 is the standard output; it is nor- mally the teletype in time-sharing or the line printer in batch. File 2 is the error file; it is an output file, nor- mally the same as file 1, except that when file 1 is diverted via a command line ’>’ operator, file 2 remains attached to the original destination, usually the terminal. It is used for error message output. These popular UNIX conventions are considered part of the C library specification. By closing 0 or 1, the default input or output may be re-directed; this can also be done on the command line by >file for output or <file for input."

This document pre-dates ditroff.   The idea/names of stdin/out/err (as opposed to fd 0, 1, 2) does not come about until Dennis does "typesetter C" which is described in K&R.

That said, my memory is fd 2 as ana error path was there in Fourth or Fifth Edition, before Lesk did this library -- i.e. it was a convention that Dennis/Ken et al were all using -- when it is realized that printing errors on in the same output flow as the standard (normal) output was problematic in a pipe stream.   

It looks to be a mixed bag in 5th edition. Cc, ac, comm and find all printf the errors. Diff uses writes to fd 2. I didn't catalog further, but this kinda looks like a developing convention, not yet fully realized. .

Further digging shows v6 is quite similar. V7 revamps everything, with printf changed to a routine that writes to stderr. Each program did this differently.

Granted, this is a small sample size. There wasn't a huge uptake of stderr/fd2 in v6 it seems, but v7 looks like it had a pass over the code to at least try for all errors going to fd2.

Warner


Warner

On Fri, Jan 20, 2023 at 5:46 PM ron minnich <rminnich@gmail.com> wrote:
I am trying to remember when fd 2 (aka stderr) became a thing. I have a vague memory that it was post-v6 but that may be way off.