WCTOMB(3P)

πŸ’– WCTOMB(3P) πŸ’–

okay bestie, so this one's from the POSIX Programmer's Manual β€” that's the manual name, keep it in your notes πŸ“


🚨 PROLOG 🚨

Real talk before we get into it: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β€” so if you're on Linux, go consult the corresponding Linux manual page for the deets on Linux behavior. Or… the interface might not even be implemented on Linux at all 😭. It's giving "check before you commit," fr fr.


✨ NAME ✨

wctomb β€” convert a wide-character code to a character

like. the name is literally the vibe. wide char β†’ multibyte. slay.


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdlib.h>

int wctomb(char *s, wchar_t wchar);

πŸ’… DESCRIPTION πŸ’…

okay so first things first, the functionality described on this reference page is aligned with the ISO C standard. And if there's any conflict between the requirements described here and the ISO C standard? That's unintentional, no cap. This volume of POSIX.1‐2017 defers to the ISO C standard. periodt.

So here's what wctomb() actually does, bestie:

The wctomb() function shall determine the number of bytes needed to represent the character corresponding to the wide-character code whose value is wchar β€” and yes, that count includes any change in the shift state, don't forget that part, it's lowkey important.

Then it shall store the character representation in the array object pointed to by s β€” and note, that representation might be possibly multiple bytes and any special bytes to change shift state πŸ¦‹. This only happens if s is not a null pointer, so watch out for that.

At most {MB_CUR_MAX} bytes shall be stored. that's the ceiling, the limit, the boundary.

And here's the special case, bestie, listen up: if wchar is 0, a null byte shall be stored, preceded by any shift sequence needed to restore the initial shift state, and wctomb() shall be left in the initial shift state. cute, clean, reset. ✨


🌸 locale stuff 🌸

The behavior of this function is affected by the LC_CTYPE category of the current locale. iykyk.

For a state-dependent encoding, this function shall be placed into its initial state by a call for which its character pointer argument, s, is a null pointer. Subsequent calls with s as other than a null pointer shall cause the internal state of the function to be altered as necessary.

A call with s as a null pointer shall cause this function to return a non-zero value if encodings have state dependency, and 0 otherwise.

⚠️ And heads up: changing the LC_CTYPE category causes the shift state of this function to be unspecified. it's giving chaos. proceed with caution πŸ’€

🧚 thread-safety tea 🧚

The wctomb() function need not be thread-safe.

😭 not the thread-safe erasure. anyway.


πŸ‘‘ one more rule πŸ‘‘

The implementation shall behave as if no function defined in this volume of POSIX.1‐2017 calls wctomb().


πŸ”₯ RETURN VALUE πŸ”₯

so like, two scenarios, bestie:

  • If s is a null pointer, wctomb() shall return a non-zero or 0 value β€” depending on whether character encodings, respectively, do or do not have state-dependent encodings.
  • If s is not a null pointer, wctomb() shall return -1 if the value of wchar does not correspond to a valid character, or it shall return the number of bytes that constitute the character corresponding to the value of wchar.
🚨 And in no case shall the value returned be greater than the value of the {MB_CUR_MAX} macro. that's a hard cap, don't @ me.

πŸ’€ ERRORS πŸ’€

The wctomb() function shall fail if:

  • EILSEQ β€” An invalid wide-character code is detected.

The following sections are informative.


🌈 EXAMPLES 🌈

None.

like. nothing. the void. 🫢


πŸ“ APPLICATION USAGE πŸ“

None.


πŸ’œ RATIONALE πŸ’œ

None.


⭐ FUTURE DIRECTIONS ⭐

None.


🌸 SEE ALSO 🌸

  • mblen()
  • mbtowc()
  • mbstowcs()
  • wcstombs()

The Base Definitions volume of POSIX.1‐2017, <stdlib.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, we ate and left no crumbs πŸ’…βœ¨ this one's brought to you by IEEE/The Open Group, dated 2017, and yeah β€” that's the source and the version and the date all wrapped up in a little bow πŸŽ€ mwah, go convert some wide chars, you've got this 🫢

πŸ“¦ where this page comes from