MEMCCHR(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… 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 NULL if no such byte exists within len bytes. 😭 (i.e. every single one of those len bytes was c, or len was 0 β€” 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