Name
setvbuf
Synopsis
Sets up I/O buffering for an open file
#include <stdio.h> intsetvbuf( FILE * restrictfp, char * restrictbuffer, intmode, size_tsize);
The setvbuf() function
specifies the buffering conditions for input and/or output using the
stream associated with the FILE
pointer fp. You may call the setvbuf() function only after the file has
been successfully opened, and before any file I/O operations have
taken place.
The mode parameter determines the
type of buffering requested. Symbolic constants for the permissible
values are defined in stdio.h
as follows:
_IOFBFFully buffered: On read and write operations, the buffer is filled completely before data appears from the source or at the destination.
_IOLBFLine buffered: On read and write operations, characters are placed in the buffer until one of them is a newline character, or until the buffer is full. Then the contents of the buffer are written to the stream. The buffer is also written to the stream whenever the program requests, from an unbuffered stream or a line-buffered stream, input which requires characters to be read from the execution environment.
_IONBFNot buffered: Data is read from or written to the file directly. The
bufferandsizeparameters are ignored.
You can provide a buffer for the file by passing its address
and size in the arguments buffer and
size. The setvbuf() function is not required to use
the buffer you provide, however. If
buffer is a null pointer, setvbuf() dynamically allocates a buffer of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access