MEMMEM(3pub)

πŸ’– MEMMEM(3pub) πŸ’–

ok so bestie, welcome to MEMMEM(3pub) from the C Programmer's Manual β€” yes we're in the publib cinematic universe today, and this one is a lil sleeper hit, i fear. it's giving "find my keys in the void." let's get into it 🫢


✨ NAME ✨

memmem β€” search for a memory block inside another memory block πŸ”πŸ¦‹

like. it's a finder. it finds things. inside other things. iconic behaviour honestly.


🌸 SYNOPSIS 🌸

#include <publib.h>
void *memmem(const void *v, size_t size,
               const void *pat, size_t patsize);

not me pulling in <publib.h> like it's nothing. slay. πŸ’…


πŸ‘‘ DESCRIPTION πŸ‘‘

okay so here's the tea, fr fr: memmem searches for the pattern pat (length patsize bytes) in the memory block v (length size bytes).

that's it. that's the whole vibe. you got a big ol' blob of memory, you got a lil baby pattern, and you want to know if that pattern is hiding in there somewhere. memmem is the one who goes looking. no cap. πŸ’–


🌈 RETURN VALUE 🌈

  • it returns a pointer to the first byte of the first occurrence it finds β€” periodt ✨
  • or NULL if it doesn't find any occurrence 😭

so like, if you get a pointer back, congrats, your pattern ate. if you get NULL, the pattern is simply not there, and that's a whole different conversation. πŸ’€


πŸŽ€ SEE ALSO πŸŽ€

(if you liked this one, the friend group is right there β€” go read them too, iykyk πŸ‘‘)


πŸ’œ AUTHOR πŸ’œ

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” thank you king, we are obsessed 🫢✨


that's the whole page bestie, mwah πŸ’…

this little gem lives in Publib, under the C Programmer's Manual, filed as MEMMEM(3pub) β€” go forth and search your memory blocks, main character πŸŒΈπŸ¦‹β­

πŸ“¦ where this page comes from