mempcpy(3)
π mempcpy β memory return-offset-pointer copy π
okay bestie, this little cutie lives in the Library Functions Manual, third section, and it's genuinely one of those "why is nobody talking about this" functions. sit down, hydrate, let's go π
π«Ά LIBRARY
Standard C library (libc, -lc). it's right there, bestie, no extra packages, no drama β¨
πΈ SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <string.h> // see memory.h(3head)
void *mempcpy(size_t n;
void dest[restrict n], const void src[restrict n],
size_t n);
heads up queen: you need that #define _GNU_SOURCE line before the include, or this whole thing is not gonna compile for you. iykyk π
π¦ DESCRIPTION
this function is similar to memcpy(3), except β and this is the part that makes me feral β it returns a pointer to one past the last written byte. like, it hands you back the spot where you stopped writing. iconic behavior fr fr π
it is equivalent to
memcpy(dest, src, n) + n
that's it. that's the whole vibe. no cap.
β¨ RETURN VALUE
dest + n.
periodt. that's the return value. just a pointer, chilling right after the bytes you wrote π
π ATTRIBUTES
for an explanation of the terms used in this section, see attributes(7).
- Interface:
mempcpy() - Attribute: Thread safety
- Value: MT-Safe
translation: it's thread-safe, babes. go wild. no locks needed, it's giving β¨caution-freeβ¨ π
π STANDARDS
GNU.
(it's a GNU thing, bestie. the GNU girls get it. that's the whole section, she's shy π)
π HISTORY
glibc 2.1.
so she's been around a minute. vintage. classic. an elder that still slays π
π₯ EXAMPLES
look at this gorgeous little function. it stacks strings like a pro:
void *
combine(void *o1, size_t s1, void *o2, size_t s2)
{
void *result = malloc(s1 + s2);
if (result != NULL)
mempcpy(mempcpy(result, o1, s1), o2, s2);
return result;
}
do you SEE the nesting?? the inner mempcpy copies o1 for s1 bytes and returns the pointer right after it, and then the outer one starts writing o2 for s2 bytes exactly there. no pointer math, no + s1 anywhere, it's just clean. obsessed. this is the main character energy of memory copying ππ
π SEE ALSO
and that's the whole page, bestie!! π§ this was Linux man-pages 6.20, dated 2026-08-10, and honestly? she ate. go copy some bytes, and remember: always check your _GNU_SOURCE. mwah ππΈ
π¦ 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: GPL-1.0-or-later
- Copyright 2002, Walter Harms <walter.harms@informatik.uni-oldenburg.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms