setvbuf

Associates a buffer with a file after the file is open and before it has been read or written to.

Library:LibC
Classification:ANSI
Service:File and Directory I/O

Syntax

  #include <stdio.h> 
   
  int setvbuf (
     FILE    *fp,
     char    *buf,
     int      mode,
     size_t   size);
  

Parameters

fp

(IN) Points to the file.

buf

(IN) Points to the buffer.

mode

(IN) Specifies the file mode that determines how to buffer the file.

Flag

Value

Description

_IOFBF

0x0040

Causes input/output to be fully buffered.

_IOLBF

0x0020

Causes output to be line buffered (the buffer is flushed when a newline character is written, when the buffer is full, or when input is requested).

_IONBF

0x0010

Causes input/output to be completely unbuffered.

size

(IN) Specifies the size of the array.

Return Values

If successful, returns 0; otherwise, returns a nonzero value and may set errno to the following:

Decimal

Constant

Description

4

EBADF

The file descriptor is invalid.

Remarks

The setvbuf function associates a buffer with the file designated by fp. This function must be called after the file has been opened and before it has been read or written.

If the buf parameter is not NULL, the array to which it points is used instead of an automatically allocated buffer. The size parameter specifies the size of the array.

See Also