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
sis a null pointer,wctomb()shall return a non-zero or0value β depending on whether character encodings, respectively, do or do not have state-dependent encodings. - If
sis not a null pointer,wctomb()shall return-1if the value ofwchardoes not correspond to a valid character, or it shall return the number of bytes that constitute the character corresponding to the value ofwchar.
π¨ 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>
π 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, 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
- 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