[Previous] [Contents] [Index] [Next]

setbuf()

Associate a buffer with a stream

Synopsis:

#include <stdio.h>

void setbuf( FILE *fp, 
             char *buffer );

Library:

libc

Description:

The setbuf() function associates the supplied buffer with the stream specified by fp. setbuf() must be used after the stream has been opened, but before any reading, writing, or seeking. If the buffer is NULL, then all input/output for the stream will be completely unbuffered. If the buffer isn't NULL, then it must point to an array that is at least BUFSIZ characters in length, and all input/output will be fully buffered.

Examples:

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

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

    buffer = (char *)malloc( BUFSIZ );
    if( buffer == NULL ) {
        return EXIT_FAILURE;
    }

    fp = fopen( "some_file", "r" );

    setbuf( fp, buffer );

    /* . */
    /* . */
    /* . */

    fclose( fp );

    free( buffer );

    return EXIT_SUCCESS;
}

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler No
Thread Yes

See also:

fopen(), setvbuf()


[Previous] [Contents] [Index] [Next]