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>


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