BUFFER_GET_TOKEN_SA_PRED(3)
π buffer_get_token_sa_pred(3) β the "read me a token, bestie" page π
okay so this is one of those pages from the Library Functions Manual (yes, that's the manual name, it's giving very "official group chat" energy π) and it's all about a function literally called buffer_get_token_sa_pred. Say that five times fast. I'll wait. π«Ά
β¨ NAME β¨
buffer_get_token_sa_pred β read token from buffer π
πΈ SYNTAX πΈ
like, the way you summon it:
#include <libowfat/stralloc.h>
#include <libowfat/buffer.h>
int buffer_get_token_sa_pred(buffer* b,stralloc* sa,
int (*predicate)(stralloc* * sa));
yes the includes are exactly those two, libowfat/stralloc.h and libowfat/buffer.h, no cap. π
π DESCRIPTION π
so here's the vibe: buffer_get_token_sa_pred appends data from b to sa until predicate(sa) returns 1 or -1. it just keeps sipping data and calling your little predicate until the predicate says "okay we're done here" (that's 1) or "ABORT" (that's -1). π₯
if predicate returns 1 once a '\n' was read, that new-line character is still appended to sa β it does not get quietly removed for you, bestie, so use stralloc_chop or stralloc_chomp to get rid of it yourself. π
and predicate can also return 0, which means "further input is required to complete the token", or -1, which means "abort and return -1". reach for -1 if your predicate wants to enforce a maximum message size, or does timeout handling, or detects a malformed message. basically -1 is the "nope, we're out" button. π
if reading from the buffer or allocating memory fails,buffer_get_token_sa_predreturns-1and setserrnoappropriately. and at that pointsamay already contain a partial token β so yeah, heads up, it's not transactional, it's just vibes. π
on success, buffer_get_token_sa_pred returns 0. slay. β
π¦ RATIONALE π¦
why does it append instead of overwriting? because that's the whole point, bestie β appending instead of overwriting means it can be used on non-blocking sockets. those signal error and set errno to EAGAIN; in this case you can simply call buffer_get_token_sa again when select or poll indicate more data is available. see? it's a "come back later" situation, not a "start over" situation. π
π SEE ALSO π
and that's the whole page, periodt. π
this one lives in the Library Functions Manual, and the footer is literally just the page name again β buffer_get_token_sa_pred(3) β because apparently even the manpage itself said "no notes, I'm perfect." iconic minimalism, honestly. πβ¨π
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms