setvbuf

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

Local Servers:nonblocking
Remote Servers:nonblocking
Classification:ANSI
Platform:NLM
Service:Stream 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.
size
(IN) Specifies the size of the array.

Return Values

The setvbuf function returns a value of 0 on success, or a nonzero value if an invalid value is given for mode or size.

Remarks

The setvbuf function can be used to associate a buffer with the file designated by fp. If this function is used, it must be called after the file has been opened and before it has been read or written. The argument mode determines how the file pointed to by fp is to be buffered, as follows:

_IOFBF

Causes input/output to be fully buffered.

_IOLBF

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

Causes input/output to be completely unbuffered.

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

See Also

fopen, setbuf

setvbuf Example

  #include <stdio.h>  
   
  main ()  
  {  
     char    *buf;  
     FILE    *fp;  
     fp = fopen ("data.fil", "r");  
     buf = malloc (1024);  
     setvbuf (fp, buf, _IOFBF, 1024);  
     fclose(fp);  
  }