WCRTOMB(3POSIX)
π¦ wcrtomb(3POSIX) β the POSIX Programmer's Manual, but make it make sense π¦
okay bestie, so this is wcrtomb from the POSIX Programmer's Manual, and I need you to clock the PROLOG before we do literally anything else, because it's important:
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 on Linux behavior), or the interface may not be implemented on Linux.
like. not me warning you about Linux behavior differences in the first sentence π read the Linux page too, ok?
β¨ NAME β¨
wcrtomb β convert a wide-character code to a character (restartable) π
that's it. that's the girl. she's restartable. she's a wide char to char converter. slay.
πΈ SYNOPSIS πΈ
#include <wchar.h>
size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps);
look at that signature. restrict twice. she's efficient, she's telling the compiler nobody's aliasing anything. queen behavior π
π DESCRIPTION π
so the functionality on this reference page is aligned with the ISO C standard. and like, if there's any conflict between the requirements described here and the ISO C standard? that conflict is unintentional. This volume of POSIX.1β2017 defers to the ISO C standard, periodt.
now. here's the tea. β
If s is a null pointer, the wcrtomb() function shall be equivalent to this call:
wcrtomb(buf, L'\0', ps)
where buf is an internal buffer. cute, right? internal buffer, not your problem.
If s is not a null pointer, wcrtomb() shall figure out how many bytes are needed to represent the character that corresponds to the wide character given by wc β including any shift sequences, don't forget the shift sequences bestie β and store the resulting bytes in the array whose first element is pointed to by s. At most {MB_CUR_MAX} bytes get stored. and if wc is a null wide character, a null byte shall be stored, preceded by any shift sequence needed to restore the initial shift state. The resulting state described shall be the initial conversion state. we love a reset. we love a clean slate. π
If ps is a null pointer, wcrtomb() shall use its own internal mbstate_t object, which is initialized at program start-up to the initial conversion state. Otherwise, the mbstate_t object pointed to by ps shall be used to completely describe the current conversion state of the associated character sequence. and the implementation shall behave as if no function defined in this volume of POSIX.1β2017 calls wcrtomb().
π¨ thewcrtomb()function need not be thread-safe if called with aNULLpsargument. i know. i KNOW. protect your threads accordingly, bestie π
The behavior of this function shall be affected by the LC_CTYPE category of the current locale. locale girlies stay winning π
and ooh, one more: wcrtomb() shall not change the setting of errno if successful. respectful king. doesn't touch your errno unless it has to.
π₯ RETURN VALUE π₯
wcrtomb() shall return the number of bytes stored in the array object β including any shift sequences, always including the shift sequences!!
when wc is not a valid wide character, an encoding error shall occur. and in that case:
- the function shall store the value of the macro
[EILSEQ]inerrno - and shall return
(size_t)-1 - and the conversion state shall be undefined π«
undefined conversion state. not vague. not "kinda weird". undefined. don't trust it after that, ok?
π ERRORS π
wcrtomb() shall fail if:
EILSEQβ an invalid wide-character code is detected.
wcrtomb() may fail if:
EINVALβpspoints to an object that contains an invalid conversion state.
and then, quote unquote: "The following sections are informative." β which is manpage for "the next bits are lore, not law" π§
π EXAMPLES π
None.
literally nothing. the example section said "i'm not doing that" π iconic honestly
π APPLICATION USAGE π
None.
also nothing!! the silence is deafening π¦
β RATIONALE β
None.
bestie there is no rationale. she just IS. main character energy, no explanation needed π
π FUTURE DIRECTIONS π
None.
the future is... also none. no notes. moving on π
π SEE ALSO π
mbsinit()wcsrtombs()
and also, from The Base Definitions volume of POSIX.1β2017: <wchar.h> π
π COPYRIGHT π
ok so legally I have to say all of this and I'm gonna say all of it, no skips:
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, and filed under WCRTOMB(3POSIX). go forth and convert your wide characters, safely, with a valid mbstate_t if you can help it π«Άβ¨
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms