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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms