MEMCCHR(9)
π MEMCCHR(9) β kernel dev manual energy
ok so bestie, we're in the kernel developer's manual (section 9, very β¨main characterβ¨ territory), and today's icon is memcchr β it helps you locate the complement of a byte in a byte string. yes, the complement. the hater of one specific byte. we'll get there. π¦
πΈ NAME πΈ
memcchr β locate the complement of a byte in byte string
like, it's memchr's chaotic sibling but instead of finding the byte you want, it finds the first one that's not that byte. it's giving "not like other bytes." π
β¨ SYNOPSIS β¨
#include <sys/libkern.h>
void *
memcchr(const void *b, int c, size_t len);
you gotta pull in <sys/libkern.h> first, no cap. then it's just: give it a buffer b, a byte c, and a length len, and it hands you back a void *. π«Ά
π DESCRIPTION π
okay so here's the whole vibe, bestie:
the memcchr() function locates the first occurrence of a byte unequal to c (converted to an unsigned char) in string b.
that's it. that's the function. it walks b and goes "nope, nope, nope, wait β THIS one isn't c" and points at it. lowkey iconic behavior honestly. π
tiny detail that fr fr matters: c gets converted to an unsigned char first, so like, don't come for it about sign weirdness. it's handled. π
π₯ RETURN VALUES π₯
- it returns a pointer to the byte located β the first one that's not
c. slay. π - or
NULLif no such byte exists withinlenbytes. π (i.e. every single one of thoselenbytes wasc, orlenwas0β she checked, she found nothing, she left.)
so yeah, always check for NULL before you dereference. literally always. π
π¦ SEE ALSO π¦
memchr(3)β the original, the blueprint, the one that finds the byte instead of dodging it. check her out too. π
π HISTORY π
the memcchr() function first appeared in FreeBSD 10.0. so she's a FreeBSD girlie from way back. respect the lineage. π
π real talk: this whole page is the Debian flavour, dated January 1, 2012, and it lives in section 9 β the kernel developer's manual. so if you're reading this, you're doing kernel things. obsessed for you. good luck out there, and remember: find the byte that isn't c, bestie. periodt. β¨πΈπ«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms