MBTOWC(3POSIX)
π MBTOWC(3POSIX) π
okay bestie, welcome to the POSIX Programmer's Manual β¨ this is the mbtowc page and we're gonna get you fluent in it, no cap.
πΈ PROLOG πΈ
real talk first: 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 check the corresponding Linux manual page for the actual tea. Or, plot twist, the interface might not even be implemented on Linux at all. π
π NAME π
mbtowc β convert a character to a wide-character code
β¨ SYNOPSIS β¨
#include <stdlib.h>
int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n);
π¦ DESCRIPTION π¦
so the functionality on this reference page is aligned with the ISO C standard. If anything here conflicts with the ISO C standard, that was not the vibe and it's unintentional β this volume of POSIX.1β2017 defers to the ISO C standard. periodt.
If s is not a null pointer, mbtowc() shall figure out how many bytes make up the character that s points to. Then it shall determine the wide-character code for the value of type wchar_t that corresponds to that character. (fun fact: the wide-character code that corresponds to the null byte is 0.) If the character is valid and pwc is not a null pointer, mbtowc() shall store the wide-character code in the object that pwc points to. slay.
The behavior of this function is affected by the LC_CTYPE category of the current locale. For a state-dependent encoding, this function gets placed into its initial state by a call where its character pointer argument, s, is a null pointer. After that, calls with s as anything 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 make this function return a non-zero value if encodings have state dependency, and 0 otherwise. If the implementation uses special bytes to change the shift state, those bytes shall not produce separate wide-character codes β they get grouped with an adjacent character instead. Changing the LC_CTYPE category causes the shift state of this function to be unspecified. π And at most n bytes of the array pointed to by s shall be examined.
The implementation shall behave as if no function defined in this volume of POSIX.1β2017 calls mbtowc().
heads up bestie: the mbtowc() function need not be thread-safe. π
π₯ RETURN VALUE π₯
If s is a null pointer, mbtowc() shall return a non-zero or 0 value β depending on whether character encodings do or do not have state-dependent encodings, respectively.
If s is not a null pointer, mbtowc() shall do one of these three:
- return
0β ifspoints to the null byte - return the number of bytes that constitute the converted character β if the next
nor fewer bytes form a valid character - return
-1and seterrnoto indicate the error β if they do not form a valid character
And in no case shall the value returned be greater than n or the value of the {MB_CUR_MAX} macro. not even once. π«Ά
π ERRORS π
The mbtowc() function shall fail if:
EILSEQβ An invalid character sequence is detected. In the POSIX locale an[EILSEQ]error cannot occur since all byte values are valid characters. iconic honestly.
The following sections are informative.
π EXAMPLES π
None.
π APPLICATION USAGE π
None.
π RATIONALE π
None.
β FUTURE DIRECTIONS β
None.
πΈ SEE ALSO πΈ
mblen()mbstowcs()wctomb()wcstombs()
Also, 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 β brought to you by IEEE/The Open Group, 2017, aka the MBTOWC(3POSIX) footer babes. go forth and convert those characters πβ¨π
π¦ 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