WCSNCPY(3POSIX)

WCSNCPY(3POSIX) πŸ’–

okay bestie, gather round, because we're reading a page straight out of the POSIX Programmer's Manual and honestly? it's giving ✨specification energy✨ in the best way. two functions, one tiny job, and a whole lot of "please don't overlap ur buffers, i'm begging". let's get into it 🫢


🌸 PROLOG 🌸

so, real talk: this manual page is part of the POSIX Programmer's Manual. that's the vibe.

but ⚠️ heads up β€” the Linux implementation of this interface may differ. like, if you're on Linux, go consult the corresponding Linux manual page for the actual Linux behavior, ok? or… plot twist… the interface might not even be implemented on Linux at all πŸ’€. check before you ship, bestie.


✨ NAME ✨

  • wcpncpy, wcsncpy β€” copy a fixed-size wide-character string, returning a pointer to its end πŸ‘‘

πŸŽ€ 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 πŸ¦‹

For wcsncpy(): the functionality described on this reference page is aligned with the ISO C standard. and if there's any conflict between what's written here and the ISO C standard? that conflict is unintentional, fr fr. this volume of POSIX.1‐2017 defers to the ISO C standard, periodt. πŸ’…

now the actual tea β˜• β€” the wcpncpy() and wcsncpy() functions shall copy not more than n wide-character codes (and btw, wide-character codes that follow a null wide-character code are not copied) from the array pointed to by ws2 to the array pointed to by ws1.

🚨 okay this is the important one: if copying takes place between objects that overlap, the behavior is undefined. like, undefined-undefined. don't do it. i'm not joking. 😭

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. padding arc πŸŽ€


πŸ‘‘ RETURN VALUE πŸ‘‘

if any null wide-character codes were written into the destination, the wcpncpy() function shall return the address of the first such null wide-character code. otherwise? it shall return &ws1[n]. iconic.

the wcsncpy() function shall return ws1. simple. clean. main character energy.

and no return values are reserved to indicate an error. so like… it won't tell you if something went wrong. it's not a snitch πŸ’€


🌈 ERRORS 🌈

no errors are defined. that's it, that's the section 🫢

The following sections are informative.


πŸ’œ EXAMPLES πŸ’œ

None.

(yes bestie, literally none. the void. nothing. πŸ•³οΈ)


πŸ“ APPLICATION USAGE πŸ“

if there is no null wide-character code in the first n wide-character codes of the array pointed to by ws2, the result is not null-terminated. ⚠️ so if you're expecting a nice little terminator at the end… it might just not be there. check ur lengths, bestie.


🧚 RATIONALE 🧚

None.


⭐ FUTURE DIRECTIONS ⭐

None.


πŸ”₯ SEE ALSO πŸ”₯

  • strncpy()
  • wcscpy()

and 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 β€” it's the final boss, no cap. 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 thing!! brought to you by IEEE/The Open Group, 2017, under the name WCSNCPY(3POSIX) β€” mwah, go copy some wide characters responsibly, bestie πŸ’…βœ¨