Node:Controlling Buffering, Previous:Flushing Buffers, Up:Stream Buffering
After opening a stream (but before any other operations have been
performed on it), you can explicitly specify what kind of buffering you
want it to have using the setvbuf
function.
The facilities listed in this section are declared in the header
file stdio.h
.
int setvbuf (FILE *stream, char *buf, int mode, size_t size) | Function |
This function is used to specify that the stream stream should
have the buffering mode mode, which can be either _IOFBF
(for full buffering), _IOLBF (for line buffering), or
_IONBF (for unbuffered input/output).
If you specify a null pointer as the buf argument, then Otherwise, buf should be a character array that can hold at least
size characters. You should not free the space for this array as
long as the stream remains open and this array remains its buffer. You
should usually either allocate it statically, or While the array remains a stream buffer, the stream I/O functions will use the buffer for their internal purposes. You shouldn't try to access the values in the array directly while the stream is using it for buffering. The |
int _IOFBF | Macro |
The value of this macro is an integer constant expression that can be
used as the mode argument to the setvbuf function to
specify that the stream should be fully buffered.
|
int _IOLBF | Macro |
The value of this macro is an integer constant expression that can be
used as the mode argument to the setvbuf function to
specify that the stream should be line buffered.
|
int _IONBF | Macro |
The value of this macro is an integer constant expression that can be
used as the mode argument to the setvbuf function to
specify that the stream should be unbuffered.
|
int BUFSIZ | Macro |
The value of this macro is an integer constant expression that is good
to use for the size argument to setvbuf . This value is
guaranteed to be at least 256 .
The value of Actually, you can get an even better value to use for the buffer size
by means of the Sometimes people also use |
void setbuf (FILE *stream, char *buf) | Function |
If buf is a null pointer, the effect of this function is
equivalent to calling setvbuf with a mode argument of
_IONBF . Otherwise, it is equivalent to calling setvbuf
with buf, and a mode of _IOFBF and a size
argument of BUFSIZ .
The |
void setbuffer (FILE *stream, char *buf, size_t size) | Function |
If buf is a null pointer, this function makes stream unbuffered.
Otherwise, it makes stream fully buffered using buf as the
buffer. The size argument specifies the length of buf.
This function is provided for compatibility with old BSD code. Use
|
void setlinebuf (FILE *stream) | Function |
This function makes stream be line buffered, and allocates the
buffer for you.
This function is provided for compatibility with old BSD code. Use
|
It is possible to query whether a given stream is line buffered or not using a non-standard function introduced in Solaris and available in the GNU C library.
int __flbf (FILE *stream) | Function |
The __flbf function will return a nonzero value in case the
stream stream is line buffered. Otherwise the return value is
zero.
This function is declared in the |
Two more extensions allow to determine the size of the buffer and how much of it is used. These functions were also introduced in Solaris.
size_t __fbufsize (FILE *stream) | Function |
The __fbufsize function return the size of the buffer in the
stream stream. This value can be used to optimize the use of the
stream.
This function is declared in the |
size_t __fpending (FILE *stream) The __fpending
|
Function |
function returns the number of bytes currently in the output buffer.
For wide-oriented stream the measuring unit is wide characters. This
function should not be used on buffers in read mode or opened read-only.
This function is declared in the |