buffer_get(3)

πŸ“¦
version 0.34 Β· 2 versions
  • 0.34 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 0.30 Β· fedora 43, fedora 44, ubuntu jammy
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– buffer_get(3) πŸ’–

okay bestie, welcome to the Library Functions Manual ✨ we're doing buffer_get today, she's the one who reads binary data out of a buffer, and she ATE πŸ’…


🌸 NAME 🌸

buffer_get β€” read binary data from buffer πŸ¦‹


✨ SYNTAX ✨

#include <libowfat/buffer.h>

ssize_t buffer_get(buffer* b,char* x,size_t len);

like. that's it. that's the whole summoning circle πŸŽ€


🫢 DESCRIPTION 🫢

so normally, buffer_get copies data to x[0], x[1], ..., x[len-1] from the beginning of a string stored in preallocated space. then it removes those len bytes from the string, and returns len. clean. iconic. no crumbs left behind πŸ’…

BUT. and this is the plot twist πŸ“ if the string has fewer than len bytes β€” but more than 0 β€” then buffer_get copies only that many bytes, and returns that number. so it gives you what it's got, ngl, it's doing its best πŸ’œ

and if the string is empty? buffer_get first uses a read operation to feed data into the string. that read operation can do two things:

  1. it may indicate end of input β€” in which case buffer_get returns 0
  2. or it may hit a read error β€” in which case buffer_get returns -1, and sets errno appropriately 😭
fr fr do not sleep on that -1. check your errno. it's giving "i tried my best and the world said no" πŸ’€

the preallocated space and the read operation are specified by b. you must initialize b using buffer_init before calling buffer_get β€” or, alternatively, use the pre-initialized buffer_0 πŸ‘‘ (she comes ready-made, main character energy, no setup required 🌈)

lowkey important: buffer_init first or buffer_0, bestie. no uninitialized buffers in this house πŸ™ˆ

πŸ‘‘ SEE ALSO πŸ‘‘

go read the whole squad, they're all slaying in their own way πŸ’–


okay that's the page!! this one lives in the Library Functions Manual, and yeah the page is so iconic she literally signs her own name again at the bottom: buffer_get(3), periodt πŸ’…βœ¨ πŸ¦‹πŸŽ€πŸ’œ