- Setvbuf
setvbuf
is a function in standard C which lets the programmer control the buffering of a file stream. It is declared in <stdio.h >; its function prototype is:"stream" is a pointer to the file stream for which the relevant buffering operations will be performed; "buf" is a char array of "size" in length, or a
null pointer ; and "mode" is the kind of buffering desired:_IOFBF
, for fully buffered,_IOLBF
for line buffered and_IONBF
for unbuffered. These three macros are defined in. setvbuf
returns zero on success or nonzero on failure.A related function,
setbuf
also controls the buffering of a file stream. Unlikesetvbuf
,setbuf
takes only two arguments. The prototype is:setbuf
's behavior is equivalent to:That is, if "buf" is not
NULL
, set the stream to fully buffered using the given buffer; otherwise, set the stream to unbuffered. If a buffer is provided tosetbuf
, it must be at leastBUFSIZ
bytes long. The function always succeeds.Example
The output of this program should be "Hello world" followed by a newline.
See also
*
fflush
*Data buffer
Wikimedia Foundation. 2010.