buffer_get...en_sa_pred(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

πŸ’– NAME πŸ’–

buffer_get_new_token_sa_pred β€” bestie, this one reads a token from a buffer πŸŽ€

So this is a page from the Library Functions Manual, and it's giving "grab me a token, but make it custom." Let's get into it 🫢


✨ SYNTAX ✨

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

int buffer_get_new_token_sa_pred(buffer* b, stralloc* sa,
                 int (*predicate)(stralloc* * sa));

🌸 DESCRIPTION 🌸

okay so. buffer_get_token_sa_pred copies data from b to sa until predicate(sa) returns 1 or -1. That's the whole vibe πŸ’…

If predicate returns 1 once a '\n' was read, that new-line character is still appended to sa β€” no cap, it's just sitting there πŸ™ˆ so use stralloc_chop or stralloc_chomp to get rid of it. And predicate can also return:

  • 0 β€” meaning further input is required to complete the token (we're not done yet, keep waiting bestie ⏳)
  • -1 β€” meaning abort and return -1. Use this if predicate wants to enforce a maximum message size, or does timeout handling, or detects a malformed message 🚩

If reading from the buffer or allocating memory fails, buffer_get_new_token_sa_pred returns -1 and sets errno appropriately 😭 and at that point sa may already contain a partial token β€” so heads up, it's not clean in there.

On success, buffer_get_new_token_sa_pred returns 0 ✨

If you want to read from a non-blocking socket, use buffer_get_token_sa_pred instead. Periodt πŸ”₯

πŸ¦‹ SEE ALSO πŸ¦‹


and that's the page, bestie πŸ’– this one lives in the Library Functions Manual and signs off as buffer_get...en_sa_pred(3) β€” no version, no date, just vibes 🌈 go read those SEE ALSOs, iykyk πŸ‘‘