WCSTOMBS(3POSIX)

πŸ’– WCSTOMBS(3POSIX) πŸ’–

okay bestie, so this is a page from the POSIX Programmer's Manual (yes, that one), and we're gonna talk about wcstombs πŸ’«


🌸 PROLOG 🌸

so like, a lil heads up before we dive in: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so pls go check the corresponding Linux manual page for the deets on Linux behavior), or honestly the interface may just not be implemented on Linux at all. πŸ’€ no cap.


✨ NAME ✨

wcstombs β€” convert a wide-character string to a character string πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>

size_t wcstombs(char *restrict s, const wchar_t *restrict pwcs,
    size_t n);

πŸ’… DESCRIPTION πŸ’…

okay so first thing: the functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional (like, we didn't mean it bestie). This volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

so what does wcstombs() actually do?? It shall convert the sequence of wide-character codes that are in the array pointed to by pwcs into a sequence of characters that begins in the initial shift state, and store these characters into the array pointed to by s. 🫢

it stops if a character would exceed the limit of n total bytes, or if a null byte is stored. Each wide-character code shall be converted as if by a call to wctomb(), except that the shift state of wctomb() shall not be affected. slay, no side effects.

The behavior of this function shall be affected by the LC_CTYPE category of the current locale. πŸ‘‘

No more than n bytes shall be modified in the array pointed to by s.

🚨 okay important: if copying takes place between objects that overlap, the behavior is undefined. like, don't do that. fr fr.

and if s is a null pointer, wcstombs() shall return the length required to convert the entire array regardless of the value of n β€” but no values are stored. it's giving "just tell me how much space I need, I'm not committing to anything yet." πŸ’β€β™€οΈ


🌈 RETURN VALUE 🌈

so if a wide-character code is encountered that does not correspond to a valid character (of one or more bytes each), wcstombs() shall return (size_t)-1. 😭 tragic.

Otherwise, wcstombs() shall return the number of bytes stored in the character array, not including any terminating null byte.

⚠️ and listen: the array shall not be null-terminated if the value returned is n. so if you get back exactly n, don't go assuming there's a cute lil \0 waiting for you at the end. there is not. πŸ™ˆ

πŸ’œ ERRORS πŸ’œ

The wcstombs() function shall fail if:

  • EILSEQ β€” A wide-character code does not correspond to a valid character. πŸ’€

The following sections are informative. (iykyk β€” that means they're the vibes, not the rules ✨)


πŸ“ EXAMPLES πŸ“

None. literally none. we're keeping it mysterious. πŸ™ˆ


🧚 APPLICATION USAGE 🧚

None. also none. iconic of them honestly.


⭐ RATIONALE ⭐

None. bestie, they had nothing to say and they said it. πŸ’…


🌸 FUTURE DIRECTIONS 🌸

None. the future is unclear but this section is empty. πŸ¦‹


πŸ‘‘ SEE ALSO πŸ‘‘

  • mblen()
  • mbtowc()
  • mbstowcs()
  • wctomb()

and also!! The Base Definitions volume of POSIX.1‐2017, <stdlib.h> πŸŽ€


okay legal bestie moment, we gotta do this part properly:

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!! brought to you by IEEE/The Open Group, dated 2017 β€” WCSTOMBS(3POSIX), and yes she ate and left no crumbs πŸ’…βœ¨πŸ¦‹