wcsncpy(3)

πŸ’– wcsncpy(3) β€” the wide-char girlies' copy function πŸ’–

okay so bestie, welcome to section 3 of the manual, aka Library Functions Manual territory, aka where all the C library calls live. today we're talking about wcsncpy, and ngl she's a little bit of a diva but we're gonna get along just fine 🫢


✨ NAME ✨

wcsncpy β€” copy a fixed-size string of wide characters

like, it copies a string of wide characters, but you tell it exactly how many. fixed-size energy. πŸ’…


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)

she's in libc! the classic! the icon! you already have her, you just gotta link her in with -lc πŸ‘‘


🌸 SYNOPSIS 🌸

#include <wchar.h>

wchar_t *wcsncpy(size_t n;
                 wchar_t dest[restrict n],
                 const wchar_t *restrict src,
                 size_t n);

Return type: wchar_t *

Args, in order:

  • wchar_t dest[restrict n] β€” where the goods go (the destination array)
  • const wchar_t *restrict src β€” where the goods come from (the source string)
  • size_t n β€” how many wide characters we're moving, periodt

and yeah, you need to #include <wchar.h> first, obviously, don't forget her 😭


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so wcsncpy() is literally just the wide-character glow-up of strncpy(3). same vibe, but for wchar_t instead of regular chars. ✨

Here's the tea β˜• β€” it copies at most n wide characters from the wide-character string pointed to by src over to the array pointed to by dest, and yes, that count includes the terminating null wide character (L'\0').

Now here's the part that makes people go "wait what 😭" β€” exactly n wide characters get written at dest. Every single time. Not "up to n". n. Exactly.

So two situations, and you gotta know which one you're in:

  • if wcslen(src) is smaller than n, then all the remaining wide characters in the array pointed to by dest get padded with null wide characters. cozy. safe. terminated. πŸŽ€
  • if wcslen(src) is greater than or equal to n, then the string pointed to by dest will not be terminated by a null wide character. NO TERMINATOR. NONE. it's giving chaotic. πŸ’€
⚠️ the strings may not overlap. like at all. do not do it.
⚠️ and this one is on you, bestie: the programmer must ensure that there is room for at least n wide characters at dest. if there isn't… that's a you problem and it's a bad one πŸ™ˆ

πŸ”₯ RETURN VALUE πŸ”₯

wcsncpy() returns dest.

that's it. that's the whole return value. she hands you back your own dest like "here u go, same thing you gave me" πŸ’…


πŸ‘‘ ATTRIBUTES πŸ‘‘

if you want the full breakdown of what these terms even mean, go read attributes(7) β€” she explains it all, go give her a visit 🫢

For wcsncpy():

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

so yeah β€” MT-Safe. multi-threaded safe. she can hang with the whole group chat at once, no drama 🌈


⭐ STANDARDS ⭐

C11, POSIX.1-2008.

standardized, certified, iconic. periodt. πŸ‘‘


🌸 HISTORY 🌸

POSIX.1-2001, C99.

so she's been around since POSIX.1-2001 and C99. an elder. a legend. respect her πŸ’œ


🧚 SEE ALSO 🧚

  • strncpy(3) β€” her narrow-char cousin, same chaotic energy, smaller characters πŸ“

πŸ’– quick vibe check recap: exactly n wchar_ts get written, src might get truncated with no null terminator if it's too long, strings can't overlap, and dest needs room for n. that's the whole thing. no cap. πŸ’…

and that's the page bestie!! this little masterpiece came to you from Linux man-pages 6.20, dated 2026-02-08, for wcsncpy(3). go forth and copy responsibly, 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-2.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms