.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)setbuf.3 6.6 (Berkeley) %G%
setbuf, setbuffer, setlinebuf, setvbuf \- assign buffering to a stream
setbuf(FILE *stream, char *buf);
setbuffer(FILE *stream, char *buf, size_t size);
setlinebuf(FILE *stream);
setvbuf(FILE *stream, char *buf, int mode, size_t size);
The three types of buffering available are unbuffered, block buffered,
When an output stream is unbuffered, information appears on the
destination file or terminal as soon as written;
when it is block buffered many characters are saved up and written as a block;
when it is line buffered characters are saved up until a newline is
output or input is read from any stream attached to a terminal device
may be used to force the block out early.
Normally all files are block buffered.
A buffer is obtained from
upon the first read or write operation on the file.
If a stream refers to a terminal
normally does) it is line buffered.
may be used at any time on any open stream
parameter must be one of the following three macros:
Except for unbuffered files, the
argument should point to a buffer at least
this buffer will be used instead of the current buffer.
only the mode is affected;
a new buffer will be allocated on the next read or write operation.
but can only change the mode of a stream
when it is not ``active'':
or immediately after a call to
The other three calls are, in effect, simply aliases
is exactly equivalent to the call
setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
is the same, except that the size of the buffer is up to the caller,
rather than being determined by the manifest constant
is exactly equivalent to the call
setvbuf(stream, (char *)NULL, _IOLBF, 0);
fopen(3), fclose(3), fread(3), malloc(3), puts(3), printf(3)
onform to ANSI X3.159-1989 (``ANSI C'').
functions are not portable to non-4.2BSD versions of UNIX.
On 4.2BSD and 4.3BSD systems,
always uses a suboptimal buffer size and should be avoided.