SETVBUF(3P)
π SETVBUF(3P) β bestie edition π
okay so this is the SETVBUF(3P) page, and it's part of the POSIX Programmer's Manual β¨ (yes, the POSIX one, not the Linux one β iykyk). So like, the Linux implementation of this interface may differ, and you should go check the corresponding Linux manual page for the deets on Linux behavior. orβ¦ it might not even be implemented on Linux at all π. vibe check accordingly.
πΈ PROLOG πΈ
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
bestie. read that again. POSIX β Linux. they're not the same thing and this page will not pretend otherwise π
β¨ NAME β¨
setvbuf β assign buffering to a stream π
π¦ SYNOPSIS π¦
#include <stdio.h>
int setvbuf(FILE *restrict stream, char *restrict buf, int type,
size_t size);
like. four args. one of them is restrict. twice. iconic behavior honestly π
π DESCRIPTION π
okay so the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional β nobody's trying to start drama. This volume of POSIX.1β2017 defers to the ISO C standard. periodt.
So here's the tea β: the setvbuf() function may be used after the stream pointed to by stream is associated with an open file, but before any other operation (other than an unsuccessful call to setvbuf()) is performed on the stream. like, the window is tiny. don't be late to it πββοΈ
The argument type determines how stream shall be buffered, as follows:
{_IOFBF}β shall cause input/output to be fully buffered.{_IOLBF}β shall cause input/output to be line buffered.{_IONBF}β shall cause input/output to be unbuffered.
If buf is not a null pointer, the array it points to may be used instead of a buffer allocated by setvbuf(), and the argument size specifies the size of the array; otherwise, size may determine the size of a buffer allocated by the setvbuf() function. The contents of the array at any time are unspecified π β like, don't peek, don't assume, don't touch.
For information about streams, see Section 2.5, Standard I/O Streams.
π«Ά RETURN VALUE π«Ά
Upon successful completion, setvbuf() shall return 0 π. Otherwise, it shall return a non-zero value if an invalid value is given for type or if the request cannot be honored, and may set errno to indicate the error. (may. not will. the ambiguity is the point, bestie π)
π ERRORS π
The setvbuf() function may fail if:
EBADFβ The file descriptor underlyingstreamis not valid. π«
The following sections are informative. (aka: the vibes-only zone from here on out β¨)
π EXAMPLES π
None.
that's it. that's the section. nothing to see here, move along π
π§ APPLICATION USAGE π§
A common source of error is allocating buffer space as an "automatic" variable in a code block, and then failing to close the stream in the same block. likeβ¦ the buffer dies but the stream lives on. tragic. don't do that π
With setvbuf(), allocating a buffer of size bytes does not necessarily imply that all of size bytes are used for the buffer area. you asked for the whole cake, you might get a slice. no cap π
Applications should note that many implementations only provide line buffering on input from terminal devices. so if your line buffering isn't line buffering, it's not you, it's the implementation π«
π RATIONALE π
None.
(truly nothing. the rationale said "no thoughts, head empty" β¨)
β FUTURE DIRECTIONS β
None.
(stable. unchanging. the main character that never gets a sequel π)
π SEE ALSO π
- Section 2.5, Standard I/O Streams
fopen()setbuf()
The Base Definitions volume of POSIX.1β2017, <stdio.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie π«Ά this one came from IEEE/The Open Group, dated 2017, and it lives at the top and bottom of the page as SETVBUF(3P) β same energy, same facts, just with way better vibes now. go forth and buffer responsibly β¨ππ
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms