![]() |
![]() |
![]() |
![]() |
Associate a buffer with a stream
#include <stdio.h> void setbuf( FILE *fp, char *buffer );
libc
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.
#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; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
![]() |
![]() |
![]() |
![]() |