buffer_get_token_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

πŸ’– buffer_get_token_pred(3) πŸ’–

okay so bestie, welcome to the Library Functions Manual ✨ this one's a lil libowfat baddie that reads you a whole token off a buffer and she's honestly so iconic for it πŸŽ€


🌸 NAME 🌸

buffer_get_token_pred β€” read token from buffer πŸ‘‘

✨ SYNTAX ✨

lowkey just include the header and you're in, no cap:

#include <libowfat/buffer.h>

ssize_t buffer_get_token_pred(buffer* b,char* x,size_t len,
                 int (*predicate)(const char* s,size_t len));

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: buffer_get_token_pred copies data from b into x[0], x[1], ..., x[len-1] β€” literally one byte at a time, main character energy β€” and it keeps going until either

  • len bytes have been read, or
  • predicate gets called on the destination string and returns nonzero πŸ‘€

and the way that predicate has options?? it's giving choose-your-own-adventure fr fr:

  • it can return 0 β€” which means "bestie I need more input to finish this token, keep going" πŸ₯Ί
  • or it can return -1 β€” which means abort and return -1 πŸ’€ use this when predicate wants to enforce a maximum message size, or does timeout handling, or detects a malformed message. periodt.

then buffer_get_token_pred returns the number of bytes copied 🫢 or -1 on error (and yes, it sets errno appropriately, she's polite like that).

ngl the -1 path is a real one β€” if your predicate bails, the whole call bails. don't sleep on that.

🌈 SEE ALSO 🌈

go read her friends too, they're all slay:


and that's the whole page babes πŸ’… this was buffer_get_token_pred(3) from the Library Functions Manual β€” k bye, ily, go read a buffer πŸ§šπŸ’œ