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
NULLif 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.7FreeBSD 6.0OpenBSD 5.4NetBSDIllumos
a whole multiverse of implementations. the way that it's been around forever... obsessed. ๐ธ
๐ BUGS ๐
ngl,glibc 2.0had a moment. ifneedlewas empty,memmem()would return a pointer to the last byte ofhaystack. which is... a choice. ๐ซ this is fixed inglibc 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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms