Path: utzoo!utgpu!attcan!uunet!seismo!sundc!pitstop!sun!quintus!ok
From: ok@quintus (Richard A. O'Keefe)
Newsgroups: comp.bugs.4bsd
Subject: linebuffering & input
Message-ID: <486@quintus.UUCP>
Date: 29 Sep 88 02:04:32 GMT
Sender: news@quintus.UUCP
Reply-To: ok@quintus (Richard A. O'Keefe)
Organization: Quintus Computer Systems, Inc.
Lines: 30

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