memmem(3)

๐Ÿ’– memmem(3) โ€” the group chat version ๐Ÿ’–

okay so bestie, you know how you can search for a word inside a text? yeah, this is that but for raw memory, and it's part of the Library Functions Manual lineup. it's giving find the thing inside the thing and honestly? iconic. ๐ŸŽ€


โœจ NAME โœจ

memmem โ€” memory search submemory ๐Ÿฆ‹

like... searching for a sub-memory inside a memory. submemory-ception. iykyk.


๐ŸŒธ LIBRARY ๐ŸŒธ

Standard C library (libc, -lc) โ€” the regular one, no fancy extra lib needed. slay.


โญ SYNOPSIS โญ

#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <string.h>  // see memory.h(3head)

void *memmem(size_t hsize, size_t nsize;
             const void haystack[hsize], size_t hsize,
             const void needle[nsize], size_t nsize);

yes bestie, you DO need that #define _GNU_SOURCE line, and yes it points you at feature_test_macros(7) if you wanna know why. also the header note sends you to memory.h(3head). the signature is written all fancy with the sizes declared up front, hsize for the haystack and nsize for the needle โ€” that's VLA notation energy, don't panic. ๐Ÿ’…


๐Ÿ‘‘ DESCRIPTION ๐Ÿ‘‘

memmem() hunts down the start of the first occurrence of the substring needle of size nsize inside the memory area haystack of size hsize.

that's it. that's the whole vibe. it's strstr() for people whose data isn't a cute little null-terminated string โ€” could have embedded \0 bytes in there and memmem does NOT care. main character energy fr fr. ๐Ÿ”ฅ


๐Ÿ’œ RETURN VALUE ๐Ÿ’œ

  • it returns a pointer to the beginning of the substring โ€” yay! ๐Ÿซถ
  • or NULL if the substring is not found โ€” tragic, but we move. ๐Ÿ˜ญ

๐ŸŒˆ ATTRIBUTES ๐ŸŒˆ

if you don't know what these terms even mean, go read attributes(7), it's like the glossary episode.

  • Interface: memmem()
  • Attribute: Thread safety
  • Value: MT-Safe

so yeah, MT-Safe โ€” multi-threaded besties can all call it at the same time, no drama, no fighting over the aux. โœจ


๐Ÿงš STANDARDS ๐Ÿงš

None.

literally none. not standardized. it's a glibc/musl/BSD-coded situation, so don't go assuming every platform on earth has it. no cap. ๐Ÿ’€


๐Ÿ“ HISTORY ๐Ÿ“

  • musl libc 0.9.7
  • FreeBSD 6.0
  • OpenBSD 5.4
  • NetBSD
  • Illumos

a whole multiverse of implementations. the way that it's been around forever... obsessed. ๐ŸŒธ


๐Ÿ’€ BUGS ๐Ÿ’€

ngl, glibc 2.0 had a moment. if needle was empty, memmem() would return a pointer to the last byte of haystack. which is... a choice. ๐Ÿซ  this is fixed in glibc 2.1, so if you're on anything modern you're fine, bestie. if you're on glibc 2.0, like... why.

๐ŸŽ€ SEE ALSO ๐ŸŽ€


and that's the whole page! written by the Linux man-pages crew, version 6.20, dated 2026-08-10, for our girl memmem(3). mwah. go search some memory. ๐Ÿ’…โœจ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms