[Previous]
[Contents]
[Next]

setbuf()

associate a buffer with a file

Synopsis:

#include <stdio.h>
void setbuf( FILE *fp, char *buffer );

Description:

The setbuf() 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. If the argument buffer is NULL, then all input/output for the file fp will be completely unbuffered. If the argument buffer isn't NULL, it must point to an array that's at least BUFSIZ characters in length, and all input/output will be fully buffered.

Examples:

#include <stdio.h>
#include <stdlib.h>

void main()
  {
    char *buffer;
    FILE *fp;

    fp = fopen( "file", "r" );
    buffer = (char *) malloc( BUFSIZ );
    setbuf( fp, buffer );

    /* ... */

    fclose( fp );
  }

Classification:

ANSI

Safety:
Interrupt handler No
Signal handler No
Thread Yes

See also:

fopen(), setvbuf()


[Previous]
[Contents]
[Next]