linebuffering & input

Richard A. O'Keefe ok at quintus
Thu Sep 29 12:04:32 AEST 1988


This problem exists in SunOS 3.2 and DYNIX "V3.0.12 NFS", so I suspect
that it is a 4.2BSD problem.

% man 3 setbuf
tells us that "when <an output stream> is line buffered, characters are
saved up until a newline is encountered or input is read from stdin."
"setlinebuf is used to change the buffering on a stream from block
buffered or unbuffered to line buffered.  Unlike setbuf and setbuffer
it can be used at any time that the file descriptor is active".

However, the ONLY streams which are flushed when input is read from
stdin are stdout and stderr.

cat >linebug.c <<'END-OF-BUG'
#include <stdio.h>
main()
    {
        char buffer[80];
        FILE *terminal = fopen("/dev/tty", "w");
        
        setlinebuf(terminal);
        fprintf(terminal, "Prompt: ");
        gets(buffer);
	exit(0);
    }
END-OF-BUG
cc -o linebug linebug.c
./linebug

The prompt does not appear until after you have typed the input.



More information about the Comp.bugs.4bsd.ucb-fixes mailing list