|
|
/usr/ucb/cc [flag . . . ] file . . .#include <stdio.h>
setbuffer(FILE *stream, char *buf, int size);
setlinebuf(FILE *stream);
By default, output to a terminal is line buffered, except for output to the standard stream stderr which is unbuffered, and all other input/output is fully buffered.
setbuffer can be used after a stream has been opened but before it is read or written. It uses the character array buf whose size is determined by the size argument instead of an automatically allocated buffer. If buf is the NULL pointer, input/output will be completely unbuffered. A manifest constant BUFSIZ, defined in the stdio.h header file, tells how big an array is needed:
char buf[BUFSIZ];
setlinebuf is used to change the buffering on a stream from block buffered or unbuffered to line buffered. Unlike setbuffer, it can be used at any time that the file descriptor is active.
A file can be changed from unbuffered or line buffered to block buffered by using freopen [see fopen(3S)]. A file can be changed from block buffered or line buffered to unbuffered by using freopen followed by setbuffer with a buffer argument of NULL.