memchr(3)
โจ memchr(3) โ the girlies' guide to finding a byte in memory โจ
okay so bestie, you know how sometimes you've got a big ol' blob of memory and you're like "where tf is that one specific character"?? that's literally what memchr is for ๐ she's a libc classic, she's from the Library Functions Manual, and she is so good at her job.
๐ธ NAME ๐ธ
memchr โ memory search character ๐
๐ LIBRARY ๐
Standard C library (libc, -lc) โ the og, the icon, the one that's already on your machine bestie ๐ซถ
๐ฆ SYNOPSIS ๐ฆ
#include <string.h> // see memory.h(3head)
void *memchr(size_t n;
const void s[n], int c, size_t n);
yes the #include line really do be looking like that, and yes there is a little comment telling you to go read memory.h(3head), we love a cross-reference ๐
๐ฅ DESCRIPTION ๐ฅ
so here's the tea โ memchr() scans the first n bytes of the memory area that s points to, looking for the first instance of c. first one only, she's not doing a whole collection tour, she finds the match and she leaves ๐
and the little detail that matters: both c and the bytes of the memory area pointed to by s get interpreted as unsigned char. no signed weirdness, no vibes-based guessing, just clean unsigned bytes โจ
โญ RETURN VALUE โญ
memchr() hands you back a pointer to the matching byte ๐ or NULL if that character just straight up does not occur in the given memory area ๐ญ (it happens to the best of us)
๐ ATTRIBUTES ๐
for an explanation of the terms used in this section, go peek at attributes(7) bestie.
memchr()โ Thread safety: MT-Safe ๐ (she is safe to use across threads, periodt)
๐ STANDARDS ๐
C11, POSIX.1-2008. she is certified, she is official, she has receipts ๐งพโจ
๐ HISTORY ๐
POSIX.1-2001, C89, SVr4, 4.3BSD. yeah she's been around since literally forever, an elder icon, we stan a legacy queen ๐
๐ซถ SEE ALSO ๐ซถ
ngl if you need to search backwards from the end, that's amemrchr(3)situation, and if you're doing wide characters that'swmemchr(3)territory. choose your fighter ๐
and that's the whole page bestie, no cap fr fr ๐ธ๐โจ
signing off from Linux man-pages 6.20, dated 2026-08-10 โ mwah, stay safe out there and don't forget to check your return value ๐ ๐๐ฆ
๐ฆ 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