From: utzoo!decvax!duke!unc!brl-bmd!mike
Newsgroups: net.unix-wizards
Title: STDIO on TTYs: Discussion and Request for Fix
Article-I.D.: brl-bmd.235
Posted: Mon Jun 28 17:07:15 1982
Received: Tue Jun 29 06:25:10 1982


My own opinion is that the present STDIO design SUCKS with respect to
handling I/O to terminals.  Using STDIO represents a giant step BACKWARDS
from the V6 getc/putc when talking to terminals, as unbuffered terminal
I/O is a machine gobbling waste.

ASSERTION 1:  The STDIO package can make whatever buffering decisions it
wants to, without affecting portability, as long as the user interface
looks the same at the top level, and flushes are done before any inputs.

ASSERTION 2:  Output to STDOUT and STDERR ought to be buffered automatically
by STDIO.  If a flush occurs under the following conditions, things should
still work right:

*)  If a newline is printed on STDOUT or STDERR, a flush occurs.

*)  If a SYS-READ is executed within the STDIO code for STDIN, a flush of
    STDOUT and STDERR should be performed.

DISCUSSION:  The first point above provides for the user seeing everything
except for a fragment of the last line being composed in the buffer, should
the program unexpectedly fault or die.  The second point provides for
prompt strings not terminated by a newline to be printed out before
doing the SYS-read call to get the reply.  In the worst case, printing
nothing but newlines, this is no worse than before.  For an average
output line of 60 characters, this represents a savings of 60X in
sys-call costs.

If the program is doing interactive I/O on files other than STDIN and
STDOUT,  then it already has to make provisions for buffer flushing, and
that will not change.  While I do not consider myself a "bit counter" or
an "efficiency fiend", grossly incorrect choices of algorithm really
tick me off, and just because something may be "Bell Code" does not mean
it is sacred.

I had heard that somebody (Berkeley?  Perdue?) had addressed this problem,
and produced a fix along the lines of what I mentioned above.  Does anybody
know if this has been done?  If not, we will do it and post the fixes
to the list.
					Smoldering,
					 -Mike