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 thann, then all the remaining wide characters in the array pointed to bydestget padded with null wide characters. cozy. safe. terminated. π - if
wcslen(src)is greater than or equal ton, then the string pointed to bydestwill 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 leastnwide characters atdest. 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: exactlynwchar_ts get written,srcmight get truncated with no null terminator if it's too long, strings can't overlap, anddestneeds room forn. 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