Associate a buffer with a stream
#include <stdio.h> void setbuf( FILE *fp, char *buffer );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The setbuf() function associates the supplied buffer with the stream specified by fp. If you want to call setbuf(), you must call it after opening the stream, but before doing any reading, writing, or seeking.
If buffer is NULL, all input/output for the stream is completely unbuffered. If buffer isn't NULL, then it must point to an array that's at least BUFSIZ characters long, and all input/output is 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 |