VMS Help
CRTL, setbuf
*Conan The Librarian
|
Associates a new buffer with an input or output file and
potentially modifies the buffering behavior.
Format
#include <stdio.h>
void setbuf (FILE *file_ptr, char *buffer);
file_ptr
A file pointer.
buffer
A pointer to a character array or a NULL pointer.
You can use the setbuf function after the specified file is
opened but before any I/O operations are performed.
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>). 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 Compaq 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. New programs should
use setvbuf instead, because it allows the programmer to bind the
buffer size at run time instead of compile time, and it returns a
result value that can be tested.