olson@fortune.UUCP (04/09/84)
From: olson (Dave Olson) What is happenening is that for V7 systems, stdout and stderr were unbuffered if output is to a terminal. This eliminated the need for fflush() when prompting, etc. It was, as you have discovered, a real loss in terms of throughput. Berkeley made some minor mods to _flsbuf(), so that stderr is still unbuffered, but stdout is line buffered. (Some versions also call fflush(stdout) whenever a getc(stdin) (or any variants thereof) is done. Other versions do not. For those versions, you have to explictly call fflush() when you are prompting for input without doing a newline. If you are reading input in any other way than from stdin, you will also have to do an fflush().) Buffering can be forced for any stream by doing setbuf(stream, buffer), and then calling fflush() at the critical points. Buffering can also be turned off completely for any stream, with setbuf(stream, NULL). Note that the above discussion applies to TERMINAL output only. stdout is default buffered in BUFSIZ chunks when output is to a pipe, file, etc. stderr is default unbuffered under all circumstances. Hope this helps, Dave Olson, Fortune Systems UUCP: {ihnp4,ucbvax!amd70}!fortune!olson ARPA: amd70!fortune!olson@BERKELEY PS: Fortune Systems stdio is based on the Berkeley version, stdout is line-buffered to a terminal.