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 a memrchr(3) situation, and if you're doing wide characters that's wmemchr(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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms