stralloc_copyb(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 πŸ’–

okay so bestie, meet stralloc_copyb β€” the function that copies data into a stralloc ✨


✨ SYNTAX ✨

first things first, you gotta pull in the header:

#include <libowfat/stralloc.h>

and here's the whole vibe of the function signature, character for character:

int stralloc_copyb(stralloc* sa,const char* buf,size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's what stralloc_copyb does, and it's honestly so thoughtful of it 🫢

It first makes sure that sa has enough space allocated to hold len bytes. Like, it does the whole "do we have room??" check for you before anything else. Then β€” and only then β€” it copies the first len bytes from buf into the stralloc. Slay. πŸ’…

Important vibe check: whatever sa was holding before? Gone. Overwritten. Truncated. It does not preserve the old data, it does not append, it does not pass go. It's giving clean slate energy, and if you were attached to what was in there, that's a you problem, bestie 😭

And now the memory drama: if stralloc_copys runs out of memory, stralloc_copys leaves sa alone and return 0 β€” otherwise it returns 1. (yes, that's exactly how the page says it, we simply report the lore as it was written πŸ“)

ngl the whole point is: it never half-does the job and leaves you with a broken stralloc. Either it works, or sa is untouched. Iconic behaviour, truly. πŸ‘‘

πŸŽ€ RETURN VALUE πŸŽ€

  • 1 β€” success, we ate, no crumbs πŸ”₯
  • 0 β€” memory allocation failure, and it's not you, it's the malloc 😭

and that's the whole page, bestie πŸ’œ this was stralloc_copyb(3) from the Library Functions Manual β€” go forth, copy bytes, be the main character of your own memory management βœ¨πŸŽ€πŸ¦‹