1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\" must display the following acknowledgement:
19 .\" This product includes software developed by the University of
20 .\" California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\" may be used to endorse or promote products derived from this software
23 .\" without specific prior written permission.
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 .\" @(#)setbuf.3 6.10 (Berkeley) 6/29/91
40 .\" Converted for Linux, Mon Nov 29 14:55:24 1993, faith@cs.unc.edu
41 .\" Added section to BUGS, Sun Mar 12 22:28:33 MET 1995,
42 .\" Thomas.Koenig@ciw.uni-karlsruhe.de
43 .\" Correction, Sun, 11 Apr 1999 15:55:18,
44 .\" Martin Vicente <martin@netadmin.dgac.fr>
45 .\" Correction, 2000-03-03, Andreas Jaeger <aj@suse.de>
46 .\" Added return value for setvbuf, aeb,
48 .TH SETBUF 3 2014-08-19 "Linux" "Linux Programmer's Manual"
50 setbuf, setbuffer, setlinebuf, setvbuf \- stream buffering operations
55 .BI "void setbuf(FILE *" stream ", char *" buf );
57 .BI "void setbuffer(FILE *" stream ", char *" buf ", size_t " size );
59 .BI "void setlinebuf(FILE *" stream );
61 .BI "int setvbuf(FILE *" stream ", char *" buf ", int " mode \
66 Feature Test Macro Requirements for glibc (see
67 .BR feature_test_macros (7)):
74 The three types of buffering available are unbuffered, block buffered, and
76 When an output stream is unbuffered, information appears on
77 the destination file or terminal as soon as written; when it is block
78 buffered many characters are saved up and written as a block; when it is
79 line buffered characters are saved up until a newline is output or input is
80 read from any stream attached to a terminal device (typically \fIstdin\fP).
83 may be used to force the block out early.
86 Normally all files are block buffered.
87 When the first I/O operation occurs on a file,
89 is called, and a buffer is obtained.
90 If a stream refers to a terminal (as
92 normally does), it is line buffered.
93 The standard error stream
95 is always unbuffered by default.
99 function may be used on any open stream to change its buffer.
102 argument must be one of the following three macros:
115 Except for unbuffered files, the
117 argument should point to a buffer at least
119 bytes long; this buffer will be used instead of the current buffer.
123 only the mode is affected; a new buffer will be allocated on the next read
127 function may be used only after opening a stream and before any other
128 operations have been performed on it.
130 The other three calls are, in effect, simply aliases for calls to
134 function is exactly equivalent to the call
137 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
142 function is the same, except that the size of the buffer is up to the
143 caller, rather than being determined by the default
147 function is exactly equivalent to the call:
150 setvbuf(stream, NULL, _IOLBF, 0);
155 returns 0 on success.
156 It returns nonzero on failure
158 is invalid or the request cannot be honored).
163 The other functions do not return a value.
165 .SS Multithreading (see pthreads(7))
172 functions are thread-safe.
178 functions conform to C89 and C99.
183 .\" .BR setlinebuf ()
184 .\" functions are not portable to versions of BSD before 4.2BSD, and
185 .\" are available under Linux since libc 4.5.21.
186 .\" On 4.2BSD and 4.3BSD systems,
188 .\" always uses a suboptimal buffer size and should be avoided.
190 You must make sure that the space that
192 points to still exists by the time
194 is closed, which also happens at program termination.
195 For example, the following is invalid:
205 printf("Hello, world!\\n");