stpncpy(3)

💖 stpncpy(3) — the copy function that actually tells you where it stopped 💖

okay bestie, we're in the Library Functions Manual and the star of today's show is stpncpy(3). she's a char * copier with main character energy and a receipt. let's get into it ✨


✨ NAME ✨

stpncpy — nonstring return-offset-pointer copy

📚 LIBRARY 📚

Standard C library (libc, -lc)


🌸 SYNOPSIS 🌸

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

char *stpncpy(size_t dsize;
              char dst[restrict dsize], const char *restrict src,
              size_t dsize);

🎀 Feature Test Macro Requirements for glibc 🎀

(peep feature_test_macros(7) if you need the lore)

stpncpy():

  • Since glibc 2.10:
    • _POSIX_C_SOURCE >= 200809L
  • Before glibc 2.10:
    • _GNU_SOURCE
yes bestie, the rules changed at glibc 2.10, that's just the vibe of it 💅

💜 DESCRIPTION 💜

So here's the tea. This function is equivalent to strncpy(3) — like, same copy energy — but she does one extra iconic thing: she hands you back a pointer to one past the last nonnull written character. that's it, that's the whole slay. 🔥

She's equivalent to this, fr fr:

memset(mempcpy(dst, src, strnlen(src, dsize)), '\0',
       dsize - strnlen(src, dsize))

like, copy what needs copying, zero-fill the rest, and return the offset. no cap. 🫶


🦋 RETURN VALUE 🦋

This function returns a pointer to one past the last non-null character written. which is, mathematically:

dest + strnlen(src, n)

that's your answer, that's the address she's pulling up on, periodt. 👑


⭐ ATTRIBUTES ⭐

For an explanation of the terms used in this section, see attributes(7).

  • Interface → stpncpy()
    • Attribute → Thread safety
    • Value → MT-Safe
MT-Safe means she can hang out in threads with all her friends, no drama. 💖

🌈 STANDARDS 🌈

POSIX.1-2008.


🌸 HISTORY 🌸

glibc 1.07. And also POSIX.1-2008. she's been around, and honestly? aging like fine wine. 🍓


💀 CAVEATS 💀

See strncpy(3).

okay so like — genuinely go read that one bestie, this girl inherits her whole personality from strncpy(3). no skimming!! 😭

👀 SEE ALSO 👀


Linux man-pages 6.20 · 2026-08-10 · mwah, that's a wrap, go forth and copy safely bestie 🎀🦋✨

📦 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