Associates a new buffer with an input or output file and potentially modifies the buffering behavior.
#include <stdio.h> void setbuf (FILE *file_ptr, char *buffer);
If buffer is a NULL pointer, then the call is equivalent to a call to setvbuf with the same file_ptr, a NULL buffer pointer, a buffering type of _IONBF (no buffering), and a buffer size of 0.
If buffer is not a NULL pointer, then the call is equivalent to a call to setvbuf with the same file_ptr, the same buffer pointer, a buffering type of _IOFBF, and a buffer size given by the value BUFSIZ (defined in <stdio.h>). You should, therefore, use BUFSIZ to allocate the buffer argument used in the call to setbuf. For example:
#include <stdio.h> . . . char my_buf[BUFSIZ]; . . . setbuf(stdout, my_buf); . . .
User programs must not depend on the contents of buffer once I/O has been performed on the stream. The DEC C RTL might or might not use buffer for any given I/O operation.
The setbuf function originally allowed programmers to substitute larger buffers in place of the system default buffers in obsolete versions of UNIX. The large default buffer sizes in modern implementations of C make the use of this function unnecessary most of the time. The setbuf function is retained in the ANSI C standard for compatibility with old programs, Digital recommends that new programs use setvbuf instead, since it allows the programmer to bind the buffer size at run time instead of compile time, and it returns a testable result value.