Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 8
Associate a buffer with a stream
#include <stdio.h>
int setvbuf( FILE *fp,
char *buf,
int mode,
size_t size );
- fp
- The stream that you want to associate with a buffer.
- buffer
- NULL, or a pointer to the buffer; see below.
- mode
- How you want the stream to be buffered:
- _IOFBF — input and output are fully buffered.
- _IOLBF — output is line buffered (i.e. the buffer
is flushed when a newline character is written, when the buffer is full,
or when input is requested).
- _IONBF — input and output are completely unbuffered.
- size
- The size of the buffer.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The setvbuf() function associates a buffer with the
stream designated by fp.
If you want to call setvbuf(), you must call it after opening the
stream, but before doing any reading, writing, or seeking.
If buf isn't NULL, the buffer it points to
is used instead of an automatically allocated buffer.
- 0
- Success.
- EINVAL
- The mode argument isn't valid.
- ENOMEM
- The buf argument is NULL,
size isn't
0, and there isn't enough memory available to allocate a
buffer.
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
char *buf;
FILE *fp;
fp = fopen( "file", "r" );
buf = malloc( 1024 );
setvbuf( fp, buf, _IOFBF, 1024 );
/* work with fp */
...
fclose( fp );
/* This is OUR buffer, so we have
* to free it. Do that AFTER
* you've closed the file.
*/
free( buf );
return EXIT_SUCCESS;
}
ANSI,
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
fopen(),
setbuf()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 194
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/setvbuf.html on line 194