byte_chr(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

πŸ’– byte_chr(3) β€” Library Functions Manual ✨

okay bestie, pull up a chair πŸͺ‘ because we're talking about byte_chr, a lil function from the Library Functions Manual and honestly? she's a whole vibe. one job, does it well, no drama. let's get into it πŸ’…


🌸 NAME 🌸

byte_chr β€” search for a byte in a string πŸ”


✨ SYNTAX ✨

like, this is how you summon her:

#include <libowfat/byte.h>

size_t byte_chr(const char *haystack,size_t len,char needle);

yes, libowfat/byte.h, that's the header, don't @ me πŸ™ˆ


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜•: byte_chr returns the smallest integer i between 0 and len-1 inclusive, such that one[i] equals needle. that's it. that's the whole personality. iconic behavior honestly πŸ‘‘

if no such integer exists β€” like, the needle is just NOT in the haystack, she's not there, gone, ghosted πŸ’€ β€” then byte_chr returns len. that's your "not found" signal, bestie. len, not -1, not NULL, not a sad little EOF. len. memorize it fr fr πŸ“

and now the part you need to know, the lowkey important caveat πŸ‘€:

byte_chr may read all bytes one[0], one[1], ..., one[len-1], even if not all the bytes are relevant to the answer.

🚨 okay so this matters!! she might peek at every single byte in that range, even the ones that have nothing to do with the answer. so if some of those bytes aren't actually valid/readable memory, that's a you problem and it's giving undefined behavior energy. don't hand her a buffer with garbage at the end and expect her not to look. she WILL look. πŸ‘€βœ¨

🌈 SEE ALSO 🌈

  • byte_rchr(3) β€” the same thing but she searches from the other end, main character energy from the back πŸŽ€

and that's the whole page, bestie 🫢 slay. this lil beauty lives in the Library Functions Manual under the name byte_chr(3) β€” and ngl there's no version or date stamped on the footer of this one, so just know she's a libowfat girlie through and through. go forth and find your bytes βœ¨πŸ’–πŸ§š