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 underlying stream is 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>


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