Guardian C Library Calls Reference Manual
Reference to Library Calls
Guardian TNS C Library Calls Reference Manual—128833 3-163
setvbuf
buf
points to the new file buffer. The buffer that buf points to must accommodate at least
BUFSIZ elements.
mode
indicates how stream will be buffered as follows:
_IOFBF I/O to be full buffered
_IOLBF I/O to be line buffered
_IONBF I/O to be unbuffered
The macros _IOFBF, _IOLBF, _IONBF are defined in the header stdioh. Full
buffering (_IOFBF) is equivalent to line buffering (_IOLBF) as both will perform
full buffering for a file opened for ANSI I/O. Unbuffering (_IONBF) disables
buffering for a file opened for ANSI I/O.
size
specifies the size of the buffer that buf points to.
Return Value
is zero if the call is successful. Otherwise, the function returns a nonzero value
under the following conditions: if an invalid value is given for mode, if a null pointer
is given for stream, if a value less then BUFSIZ is given for size, or if there is lack of
memory space for the requested buffer.
Usage Guidelines
•
The setvbuf function can be used only after the stream pointed to by stream has been
associated with an open file and before any other operation is performed on the
stream.
•
If buf is null, the C run-time library allocates a buffer with the size of BUFSIZ. If
buf is not null, the function attaches the buffer pointed to be buf as a user-supplied
buffer to a file opened for ANSI I/O. BUFSIZ is used as the size of the buffer for all
circumstances.
•
BUFSIZ is a predefined object-like macro that specifies the size in bytes of the
buffers C uses for streams. It is defined in the header stdioh.
•
Once a user calls setvbuf with mode of _IONBF, which disables buffering, all input
and output operations on the specified file generate immediate I/O requests.