byte_chr(3)
π 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 β¨ππ§
π¦ 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