stdio buffering considered harmful

dan at bbncd dan at bbncd
Sat Jul 30 04:31:18 AEST 1983


From:  Dan Franklin <dan at bbncd>

Thanks for the comments.  Since no one came up with anything better than
using the environment, that's what I will do.  In case anyone else is
interested in solving this problem, here's exactly how I plan to do it (when I
finally get around to it).  I plan to have three choices, each set by assigning
a value to STDOUT in the environment:

STDOUT=NBUF     # no buffering
STDOUT=LBUF     # line buffering
STDOUT=BBUF     # block buffering

If there is an explicit setbuf(stdout,...) in the program, it seems like the
environment setting ought to override it, at least in the case where the
environment specifies less buffering than the setbuf.  I plan to have it
override all the time.  The environment variable would also override stdio's
determination of the buffering to use based on isatty().

The same mechanism will also work for STDERR.  (STDERR=BBUF could be handy when
you have a program producing lots of error output, all unbuffered.)

	Dan Franklin



More information about the Comp.unix.wizards mailing list