2 .\" Copyright (c) 1980, 1991 Regents of the University of California.
3 .\" All rights reserved.
5 .\" This code is derived from software contributed to Berkeley by
6 .\" the American National Standards Committee X3, on Information
7 .\" Processing Systems.
9 .\" SPDX-License-Identifier: BSD-4-Clause-UC
11 .\" @(#)setbuf.3 6.10 (Berkeley) 6/29/91
13 .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu
14 .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995,
15 .\" Thomas.Koenig@ciw.uni-karlsruhe.de
16 .\" Correction, Sun, 11 Apr 1999 15:55:18,
17 .\" Martin Vicente <martin@netadmin.dgac.fr>
18 .\" Correction, 2000-03-03, Andreas Jaeger <aj@suse.de>
19 .\" Added return value for setvbuf, aeb,
21 .TH setbuf 3 (date) "Linux man-pages (unreleased)"
23 setbuf, setbuffer, setlinebuf, setvbuf \- stream buffering operations
26 .RI ( libc ", " \-lc )
31 .BI "int setvbuf(FILE *restrict " stream ", char " buf "[restrict ." size ],
32 .BI " int " mode ", size_t " size );
34 .BI "void setbuf(FILE *restrict " stream ", char *restrict " buf );
35 .BI "void setbuffer(FILE *restrict " stream ", char " buf "[restrict ." size ],
36 .BI " size_t " size );
37 .BI "void setlinebuf(FILE *" stream );
41 Feature Test Macro Requirements for glibc (see
42 .BR feature_test_macros (7)):
50 glibc 2.19 and earlier:
54 The three types of buffering available are unbuffered, block buffered, and
56 When an output stream is unbuffered, information appears on
57 the destination file or terminal as soon as written; when it is block
58 buffered, many characters are saved up and written as a block; when it is
59 line buffered, characters are saved up until a newline is output or input is
60 read from any stream attached to a terminal device (typically \fIstdin\fP).
63 may be used to force the block out early.
67 Normally all files are block buffered.
68 If a stream refers to a terminal (as
70 normally does), it is line buffered.
71 The standard error stream
73 is always unbuffered by default.
77 function may be used on any open stream to change its buffer.
80 argument must be one of the following three macros:
93 Except for unbuffered files, the
95 argument should point to a buffer at least
97 bytes long; this buffer will be used instead of the current buffer.
101 only the mode is affected; a new buffer will be allocated on the next read
105 function may be used only after opening a stream and before any other
106 operations have been performed on it.
108 The other three calls are, in effect, simply aliases for calls to
112 function is exactly equivalent to the call
115 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
120 function is the same, except that the size of the buffer is up to the
121 caller, rather than being determined by the default
125 function is exactly equivalent to the call:
128 setvbuf(stream, NULL, _IOLBF, 0);
133 returns 0 on success.
134 It returns nonzero on failure
136 is invalid or the request cannot be honored).
141 The other functions do not return a value.
143 For an explanation of the terms used in this section, see
149 Interface Attribute Value
157 T} Thread safety MT-Safe
173 .\" https://www.austingroupbugs.net/view.php?id=397#c799
174 .\" 0000397: setbuf and errno
177 is unspecified after a call to
179 and further notes that, since the value of
181 is not required to be unchanged after a successful call to
183 applications should instead use
185 in order to detect errors.
190 .\" .BR setlinebuf ()
191 .\" functions are not portable to versions of BSD before 4.2BSD, and
192 .\" are available under Linux since libc 4.5.21.
193 .\" On 4.2BSD and 4.3BSD systems,
195 .\" always uses a suboptimal buffer size and should be avoided.
197 You must make sure that the space that
199 points to still exists by the time
201 is closed, which also happens at program termination.
202 For example, the following is invalid:
204 .\" SRC BEGIN (setbuf.c)
214 printf("Hello, world!\en");