BSD 4_4 development
[unix-history] / usr / share / man / cat3 / setbuffer.0
SETBUF(3) BSD Programmer's Manual SETBUF(3)
N\bNA\bAM\bME\bE
s\bse\bet\btb\bbu\buf\bf, s\bse\bet\btb\bbu\buf\bff\bfe\ber\br, s\bse\bet\btl\bli\bin\bne\beb\bbu\buf\bf, s\bse\bet\btv\bvb\bbu\buf\bf - stream buffering operations
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
#\b#i\bin\bnc\bcl\blu\bud\bde\be <\b<s\bst\btd\bdi\bio\bo.\b.h\bh>\b>
_\bv_\bo_\bi_\bd
s\bse\bet\btb\bbu\buf\bf(_\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm, _\bc_\bh_\ba_\br _\b*_\bb_\bu_\bf);
_\bv_\bo_\bi_\bd
s\bse\bet\btb\bbu\buf\bff\bfe\ber\br(_\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm, _\bc_\bh_\ba_\br _\b*_\bb_\bu_\bf, _\bs_\bi_\bz_\be_\b__\bt _\bs_\bi_\bz_\be);
_\bi_\bn_\bt
s\bse\bet\btl\bli\bin\bne\beb\bbu\buf\bf(_\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm);
_\bi_\bn_\bt
s\bse\bet\btv\bvb\bbu\buf\bf(_\bF_\bI_\bL_\bE _\b*_\bs_\bt_\br_\be_\ba_\bm, _\bc_\bh_\ba_\br _\b*_\bb_\bu_\bf, _\bi_\bn_\bt _\bm_\bo_\bd_\be, _\bs_\bi_\bz_\be_\b__\bt _\bs_\bi_\bz_\be);
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The three types of buffering available are unbuffered, block buffered,
and line buffered. When an output stream is unbuffered, information ap-
pears 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 (typically
stdin). The function fflush(3) may be used to force the block out early.
(See fclose(3).)
Normally all files are block buffered. When the first I/O operation oc-
curs on a file, malloc(3) is called, and an optimally-sized buffer is ob-
tained. If a stream refers to a terminal (as _\bs_\bt_\bd_\bo_\bu_\bt normally does) it is
line buffered. The standard error stream _\bs_\bt_\bd_\be_\br_\br is always unbuffered.
The s\bse\bet\btv\bvb\bbu\buf\bf() function may be used to alter the buffering behavior of a
stream. The _\bm_\bo_\bd_\be parameter must be one of the following three macros:
_IONBF unbuffered
_IOLBF line buffered
_IOFBF fully buffered
The _\bs_\bi_\bz_\be parameter may be given as zero to obtain deferred optimal-size
buffer allocation as usual. If it is not zero, then except for un-
buffered files, the _\bb_\bu_\bf argument should point to a buffer at least _\bs_\bi_\bz_\be
bytes long; this buffer will be used instead of the current buffer. (If
the _\bs_\bi_\bz_\be argument is not zero but _\bb_\bu_\bf is NULL, a buffer of the given size
will be allocated immediately, and released on close. This is an exten-
sion to ANSI C; portable code should use a size of 0 with any NULL
buffer.)
The s\bse\bet\btv\bvb\bbu\buf\bf() function may be used at any time, but may have peculiar
side effects (such as discarding input or flushing output) if the stream
is ``active''. Portable applications should call it only once on any
given stream, and before any I/O is performed.
The other three calls are, in effect, simply aliases for calls to
s\bse\bet\btv\bvb\bbu\buf\bf(). Except for the lack of a return value, the s\bse\bet\btb\bbu\buf\bf() function
is exactly equivalent to the call
setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
The s\bse\bet\btb\bbu\buf\bff\bfe\ber\br() function is the same, except that the size of the buffer
is up to the caller, rather than being determined by the default BUFSIZ.
The s\bse\bet\btl\bli\bin\bne\beb\bbu\buf\bf() function is exactly equivalent to the call:
setvbuf(stream, (char *)NULL, _IOLBF, 0);
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bES\bS
The s\bse\bet\btv\bvb\bbu\buf\bf() function returns 0 on success, or EOF if the request cannot
be honored (note that the stream is still functional in this case).
The s\bse\bet\btl\bli\bin\bne\beb\bbu\buf\bf() function returns what the equivalent s\bse\bet\btv\bvb\bbu\buf\bf() would
have returned.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
fopen(3), fclose(3), fread(3), malloc(3), puts(3), printf(3)
S\bST\bTA\bAN\bND\bDA\bAR\bRD\bDS\bS
The s\bse\bet\btb\bbu\buf\bf() and s\bse\bet\btv\bvb\bbu\buf\bf() functions conform to ANSI C X3.159-1989
(``ANSI C '').
B\bBU\bUG\bGS\bS
The s\bse\bet\btb\bbu\buf\bff\bfe\ber\br() and s\bse\bet\btl\bli\bin\bne\beb\bbu\buf\bf() functions are not portable to versions
of BSD before 4.2BSD. On 4.2BSD and 4.3BSD systems, s\bse\bet\btb\bbu\buf\bf() always uses
a suboptimal buffer size and should be avoided.
4th Berkeley Distribution June 4, 1993 2