Name

setvbuf

Synopsis

Sets up I/O buffering for an open file

#include <stdio.h>
intsetvbuf( FILE * restrict fp, char * restrict buffer, int mode,
             size_t size );

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:

_IOFBF

Fully buffered: On read and write operations, the buffer is filled completely before data appears from the source or at the destination.

_IOLBF

Line 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.

_IONBF

Not buffered: Data is read from or written to the file directly. The buffer and size parameters 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 ...

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.