buffer(3)

πŸ“¦
version 0.34 Β· 3 versions
, in debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸŽ€ buffer(3) πŸŽ€

okay bestie, come sit with me, we're gonna talk about buffer.h β€” the generic read/write buffering header from libowfat, and yes it lives in section 3 of the Library Functions Manual πŸ’…


✨ NAME ✨

buffer.h β€” generic read/write buffering πŸ¦‹

Like, it's a buffer. For reading. For writing. Generic. That's the whole vibe.


🌸 SYNTAX 🌸

#include <libowfat/buffer.h>

  buffer* buffer_0;   /* like stdio's stdin */
  buffer* buffer_1;   /* like stdio's stdout */
  buffer* buffer_2;   /* like stdio's stderr */

so you've got three pre-made buffers hanging out for you, and they're literally the glow-ups of the stdio trio you already know:

  • buffer_0 β€” it's giving stdin ✨
  • buffer_1 β€” it's giving stdout ✨
  • buffer_2 β€” it's giving stderr ✨

πŸ’– DESCRIPTION πŸ’–

buffer.h hands you a generic buffer interface you can use for read buffering and write buffering. Two modes, one header. Versatile queen. πŸ‘‘

Heads up though: buffers must be initialized with buffer_init first. No buffer_init, no buffer. Periodt.

Also β€” and this is the important part, bestie β€” a buffer can only be used for reading OR writing at the same time, not both. Pick a lane. It's not doing the both-thing. πŸ™ˆ

And here's the tea, the part where libowfat does NOT behave like stdio does: these write buffers are not flushed automatically at program termination. 😭 Like, your program can just end and that data is still sitting there. You have to manually call one of these:

  • buffer_flush
  • buffer_putsflush
  • buffer_putflush
  • buffer_putnlflush

Manually. With your own hands. Every time. No auto-save, no autosave, no nothing. πŸ’€


🌈 EXAMPLE 🌈

For example read buffer code, go peek at buffer_init(3) β€” it's right there in the SEE ALSO, iykyk. 🫢

But here's the typical code for printing an error message on stderr, and honestly it ate:

#include <libowfat/buffer.h>

buffer_puts(buffer_2,"error: got only ");
buffer_putulong(buffer_2,got);
buffer_puts(buffer_2," bytes, but expected at least ");
buffer_putulong(buffer_2,expected);
buffer_putsflush(buffer_2," bytes!");

Notice how the first four lines just put stuff into buffer_2 β€” and then the last one is buffer_putsflush? That's the flush doing its job, because remember: no automatic flushing around here. The final " bytes!" rides out with the flush. So cute. So intentional. πŸŽ€


⭐ SEE ALSO ⭐


and that's the page, bestie!! πŸ’– this was buffer(3) from the Library Functions Manual β€” section 3, where all the library functions live. the footer on this one is literally just buffer(3) with no version number and no date attached, so no source or release info to pass along, just the page name twice because the manpage gods love symmetry ✨ slay, go flush your buffers 🫢🌸