memccpy(3)

✨ memccpy(3) ✨

okay bestie, gather round 🫢 this one lives in the Library Functions Manual, section 3, so it's a proper libc function, not some command you type at the prompt. And lowkey? Her name is memccpy, and she is not the string-copying girlie you think she is. Let me put you on πŸ”₯


🌸 NAME 🌸

memccpy β€” memory until-and-including-character copy


πŸ’œ LIBRARY πŸ’œ

Standard C library (libc, -lc). Yes, the plain one, no special linker flags, we love a low-maintenance queen πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <string.h>  // see memory.h(3head)

void *memccpy(size_t n;
              void dest[restrict n], const void src[restrict n],
              int c, size_t n);

πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the vibe. memccpy() copies no more than n bytes from the memory area src into the memory area dest, and it stops when the character c is found β€” and yes, c itself gets copied too, it's included, no crumbs left behind πŸ’–

That "stop at c but copy c" behaviour is literally the whole personality of this function, iykyk.

⚠️ If the memory areas overlap, the results are undefined. Not "a little weird", not "maybe fine" β€” undefined. Do not do it. That's it, that's the warning 🚩

πŸ’€ RETURN VALUE πŸ’€

memccpy() hands you back a pointer to the next character in dest after c β€” like, the spot right after the character it stopped on, main character energy ✨

OR, if c was not found in the first n characters of src, you get NULL. No c, no pointer. Simple as 🫢


🧚 ATTRIBUTES 🧚

For what all these terms even mean, go read attributes(7), she explains it better than me:

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

Translation: she's MT-Safe, so multiple threads can hang out with her at the same time, no drama 🌈


⭐ STANDARDS ⭐

POSIX.1-2008. Certified, standardised, iconic πŸ‘‘


πŸ“ HISTORY πŸ“

POSIX.1-2001, SVr4, 4.3BSD. She's been around. Veteran behaviour πŸ’…


πŸ™ˆ CAVEATS πŸ™ˆ

okay this part matters, listen up bestie πŸ“’

This function has recently (since C23) started being misused for copying strings with truncation. That is not its intended use, and it is most likely to result in bugs if you use it for that. Not a vibe. Not the move. 🚫

πŸ”₯ The reason is that memccpy() was designed for a quite different (and niche) task: implementing fgets(3). That's her job. That's what she was built for. Respect the niche.

🌟 SEE ALSO 🌟


and that's the whole page, bestie!! πŸ’– you just read the memccpy(3) entry from Linux man-pages 6.20, dated 2026-08-10 β€” go forth, copy your memory until-and-including characters, and please, please don't overlap your buffers πŸŽ€πŸ’œπŸ¦‹

πŸ“¦ 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