buffer_getline_sa(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_getline_sa β€” the manual, but make it make sense

okay bestie, welcome to section 3 of the Library Functions Manual πŸŽ€ this is buffer_getline_sa(3), and yes she's a libowfat girlie ✨


🌸 NAME 🌸

buffer_getline_sa β€” read a line from a buffer. that's it, that's the whole job description πŸ’…


✨ SYNTAX ✨

#include <libowfat/stralloc.h>
#include <libowfat/buffer.h>

int buffer_getline_sa(buffer* b,stralloc* sa);

two includes, one function, zero drama 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, bestie: buffer_getline_sa takes data from b and appends it to sa until it hits a '\n'. note the word appends β€” she does NOT overwrite the previous content of sa, okay? the old stuff stays. and the new-line itself? also gets appended to sa. iconic behaviour honestly πŸ‘‘

now for the part where we gotta be real: if reading from the buffer fails, or if allocating memory fails, buffer_getline_sa returns -1 and sets errno appropriately 😭 and at that exact moment, sa may be empty, or it may already contain a partial token. yeah. partial. like it stopped mid-vibe. so watch out for that πŸ’€


⭐ RETURN VALUE ⭐

  • -1 on error β€” and she sets errno while she's at it, no cap
  • 0 on EOF
  • 1 when successful πŸŽ‰

three possible outcomes, zero mystery 🌈


πŸ’œ RATIONALE πŸ’œ

why does she append instead of overwriting? because bestie, that's what makes her usable on non-blocking sockets πŸ”₯

those sockets signal error and set errno to EAGAIN, and when that happens you don't panic β€” you literally just call buffer_getline_sa again later, once select or poll tell you more data is available. main character energy: she waits for her moment and then she comes back πŸ’…βœ¨


πŸ‘‘ SEE ALSO πŸ‘‘

go read your sisters, they're just as iconic πŸ¦‹


no cap: on error, sa might be empty or hold a partial token. plan accordingly, bestie πŸ™ˆ

and that's the whole page!! brought to you by the Library Functions Manual, filed under buffer_getline_sa(3) in section 3 πŸŽ€ mwah, go read a buffer, periodt πŸ’–