HP C/iX Library Reference Manual (30026-90004)

Chapter 5 309
HP C/iX Library Function Descriptions
setvbuf
setvbuf
Assigns a buffer and buffering method to an open stream.
Syntax
#include <stdio.h>
int setvbuf (FILE *
stream
, char *
buffer
,
int
type
, size_t
size
);
Parameters
stream
A pointer to an open stream.
buffer
Either a pointer to a character array for buffered I/O, or null.
type
The method of buffering.
size
The size of the buffer.
Return Values
0 Success.
0 An error occurred.
Description
The setvbuf function enables you to assign a character array for buffering, and also
provides the means to specify the size of the buffer to be used (
size
) and the type of
buffering to be done (
type
). Acceptable values for
type
(defined in <stdio.h>) include:
_IOFBF Input/output is fully buffered.
_IOLBF Output is line buffered. The buffer is flushed each time a new line is
written, the buffer is full, or input is requested.
_IONBF Input/output is completely unbuffered.
If
type
_IONBF is specified,
stream
is totally unbuffered. Because no buffer is needed,
values for
buffer
and
size
are ignored.
If
buffer
is the null pointer and type is specified as _IOFBF or _IOLBF, setvbuf()
automatically allocates a buffer of
size
bytes through a call to malloc().
If
size
is zero, a buffer of size BUFSIZ is used. This behavior can be used to change the
buffer size for a stream even if you still want the standard I/O system to automatically
allocate the buffer. This is particularly useful when a buffer larger than the specified
BUFSIZ is needed.
Examples
In the following examples, the following two calls, though different, are functionally