1SETBUF(3) Linux Programmer's Manual SETBUF(3)
2
3
4
6 setbuf, setbuffer, setlinebuf, setvbuf - stream buffering operations
7
9 #include <stdio.h>
10
11 int setvbuf(FILE *restrict stream, char *restrict buf,
12 int mode, size_t size);
13
14 void setbuf(FILE *restrict stream, char *restrict buf);
15 void setbuffer(FILE *restrict stream, char *restrict buf,
16 size_t size);
17 void setlinebuf(FILE *stream);
18
19 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
20
21 setbuffer(), setlinebuf():
22 Since glibc 2.19:
23 _DEFAULT_SOURCE
24 Glibc 2.19 and earlier:
25 _BSD_SOURCE
26
28 The three types of buffering available are unbuffered, block buffered,
29 and line buffered. When an output stream is unbuffered, information
30 appears on the destination file or terminal as soon as written; when it
31 is block buffered, many characters are saved up and written as a block;
32 when it is line buffered, characters are saved up until a newline is
33 output or input is read from any stream attached to a terminal device
34 (typically stdin). The function fflush(3) may be used to force the
35 block out early. (See fclose(3).)
36
37 Normally all files are block buffered. If a stream refers to a termi‐
38 nal (as stdout normally does), it is line buffered. The standard error
39 stream stderr is always unbuffered by default.
40
41 The setvbuf() function may be used on any open stream to change its
42 buffer. The mode argument must be one of the following three macros:
43
44 _IONBF unbuffered
45
46 _IOLBF line buffered
47
48 _IOFBF fully buffered
49
50 Except for unbuffered files, the buf argument should point to a buffer
51 at least size bytes long; this buffer will be used instead of the cur‐
52 rent buffer. If the argument buf is NULL, only the mode is affected; a
53 new buffer will be allocated on the next read or write operation. The
54 setvbuf() function may be used only after opening a stream and before
55 any other operations have been performed on it.
56
57 The other three calls are, in effect, simply aliases for calls to
58 setvbuf(). The setbuf() function is exactly equivalent to the call
59
60 setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
61
62 The setbuffer() function is the same, except that the size of the buf‐
63 fer is up to the caller, rather than being determined by the default
64 BUFSIZ. The setlinebuf() function is exactly equivalent to the call:
65
66 setvbuf(stream, NULL, _IOLBF, 0);
67
69 The function setvbuf() returns 0 on success. It returns nonzero on
70 failure (mode is invalid or the request cannot be honored). It may set
71 errno on failure.
72
73 The other functions do not return a value.
74