1SETVBUF(3P) POSIX Programmer's Manual SETVBUF(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 setvbuf — assign buffering to a stream
14
16 #include <stdio.h>
17
18 int setvbuf(FILE *restrict stream, char *restrict buf, int type,
19 size_t size);
20
22 The functionality described on this reference page is aligned with the
23 ISO C standard. Any conflict between the requirements described here
24 and the ISO C standard is unintentional. This volume of POSIX.1‐2008
25 defers to the ISO C standard.
26
27 The setvbuf() function may be used after the stream pointed to by
28 stream is associated with an open file but before any other operation
29 (other than an unsuccessful call to setvbuf()) is performed on the
30 stream. The argument type determines how stream shall be buffered, as
31 follows:
32
33 * {_IOFBF} shall cause input/output to be fully buffered.
34
35 * {_IOLBF} shall cause input/output to be line buffered.
36
37 * {_IONBF} shall cause input/output to be unbuffered.
38
39 If buf is not a null pointer, the array it points to may be used
40 instead of a buffer allocated by setvbuf() and the argument size speci‐
41 fies the size of the array; otherwise, size may determine the size of a
42 buffer allocated by the setvbuf() function. The contents of the array
43 at any time are unspecified.
44
45 For information about streams, see Section 2.5, Standard I/O Streams.
46
48 Upon successful completion, setvbuf() shall return 0. Otherwise, it
49 shall return a non-zero value if an invalid value is given for type or
50 if the request cannot be honored, and may set errno to indicate the
51 error.
52
54 The setvbuf() function may fail if:
55
56 EBADF The file descriptor underlying stream is not valid.
57
58 The following sections are informative.
59
61 None.
62
64 A common source of error is allocating buffer space as an ``automatic''
65 variable in a code block, and then failing to close the stream in the
66 same block.
67
68 With setvbuf(), allocating a buffer of size bytes does not necessarily
69 imply that all of size bytes are used for the buffer area.
70
71 Applications should note that many implementations only provide line
72 buffering on input from terminal devices.
73
75 None.
76
78 None.
79
81 Section 2.5, Standard I/O Streams, fopen(), setbuf()
82
83 The Base Definitions volume of POSIX.1‐2008, <stdio.h>
84
86 Portions of this text are reprinted and reproduced in electronic form
87 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
88 -- Portable Operating System Interface (POSIX), The Open Group Base
89 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
90 cal and Electronics Engineers, Inc and The Open Group. (This is
91 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
92 event of any discrepancy between this version and the original IEEE and
93 The Open Group Standard, the original IEEE and The Open Group Standard
94 is the referee document. The original Standard can be obtained online
95 at http://www.unix.org/online.html .
96
97 Any typographical or formatting errors that appear in this page are
98 most likely to have been introduced during the conversion of the source
99 files to man page format. To report such errors, see https://www.ker‐
100 nel.org/doc/man-pages/reporting_bugs.html .
101
102
103
104IEEE/The Open Group 2013 SETVBUF(3P)