WCSNCPY(3P)
π WCSNCPY(3P) β the POSIX Programmer's Manual one π
okay bestie, so this is a page straight outta the POSIX Programmer's Manual. heads up tho: the Linux implementation of this interface may be different (go check the matching Linux man page for the deets on Linux behavior), or honestly the interface might not even be implemented on Linux at all. π« not me warning you first thing.
β¨ PROLOG β¨
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
πΈ NAME πΈ
wcpncpy, wcsncpy β copy a fixed-size wide-character string, and (for one of them) hand you back a pointer to its end. so iconic of them.
π SYNOPSIS π
#include <wchar.h>
wchar_t *wcpncpy(wchar_t restrict *ws1, const wchar_t *restrict ws2,
size_t n);
wchar_t *wcsncpy(wchar_t *restrict ws1, const wchar_t *restrict ws2,
size_t n);
π DESCRIPTION π
Okay so for wcsncpy() specifically: the functionality on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that conflict is unintentional β and this volume of POSIX.1β2017 defers to the ISO C standard. periodt.
Now the actual vibe: wcpncpy() and wcsncpy() shall copy not more than n wide-character codes from the array pointed to by ws2 over to the array pointed to by ws1. and bestie, listen β wide-character codes that follow a null wide-character code are not copied. nope. not invited to the party. π
β οΈ if copying takes place between objects that overlap, the behavior is undefined. do not do this. i'm literally begging you. π
And if the array pointed to by ws2 is a wide-character string that's shorter than n wide-character codes? then null wide-character codes shall be appended to the copy in the array pointed to by ws1, until n wide-character codes in all are written. she pads. she fills. she completes the assignment. β¨
π₯ RETURN VALUE π₯
If any null wide-character codes were written into the destination, wcpncpy() shall return the address of the first such null wide-character code. otherwise? it shall return &ws1[n]. slay.
wcsncpy() shall return ws1. that's it. that's the whole return value. no drama. π
No return values are reserved to indicate an error. so like, don't go looking for one. there isn't one. π§
π ERRORS π
No errors are defined.
The following sections are informative. (translation: the next few sections are the "for your information, bestie" section, not the hard requirements. iykyk.)
π EXAMPLES π
None.
(genuinely nothing. zero. the example section said "not me, not today". π)
π¦ APPLICATION USAGE π¦
Okay this one matters, so listen up: if there is no null wide-character code in the first n wide-character codes of the array pointed to by ws2, then the result is not null-terminated. not terminated. at all. you have to deal with that yourself. good luck and stay safe. π«Ά
β RATIONALE β
None.
πΈ FUTURE DIRECTIONS πΈ
None.
π SEE ALSO π
strncpy()wcscpy()
The Base Definitions volume of POSIX.1β2017, <wchar.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie, mwah π this one came courtesy of IEEE/The Open Group, dated 2017 β thanks for coming to my ted talk, go copy some wide chars responsibly, and remember: no overlapping objects, no exceptions π β¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms