MBRTOWC(3)
๐ MBRTOWC(3) โ Library Functions Manual ๐
okay bestie, gather round: this is the glow-up for mbrtowc(3), mbrtoc16(3), and mbrtoc32(3) โ the restartable wide-character conversion trio. theyโre iconic, theyโre useful, and yes, they have lore. โจ
๐ธ NAME ๐ธ
mbrtowc, mbrtoc16, mbrtoc32 โ convert a character to a wide-character code (restartable)
๐ LIBRARY ๐
Standard C Library (libc, -lc)
โจ SYNOPSIS โจ
#include <wchar.h>
size_t
mbrtowc(wchar_t * restrict pc, const char * restrict s, size_t n,
mbstate_t * restrict ps);
#include <uchar.h>
size_t
mbrtoc16(char16_t * restrict pc, const char * restrict s, size_t n,
mbstate_t * restrict ps);
size_t
mbrtoc32(char32_t * restrict pc, const char * restrict s, size_t n,
mbstate_t * restrict ps);
๐ฆ DESCRIPTION ๐ฆ
okay so picture this: mbrtowc(), mbrtoc16(), and mbrtoc32() inspect at most n bytes pointed to by s to determine how many bytes are needed to complete the next multibyte character. ๐
If a character can be completed, and pc is not NULL, the wide character represented by s gets stored in the wchar_t, char16_t, or char32_t that pc points to. slay. ๐
If s is NULL, these functions behave as if pc was NULL, s was an empty string (""), and n was 1. no cap.
The mbstate_t argument, ps, is used to keep track of the shift state. If it is NULL, these functions use an internal, static mbstate_t object, which is initialized to the initial conversion state at program startup. ๐
And the way that a single char16_t is not large enough to represent certain multibyte characters means mbrtoc16() may need to be invoked multiple times to convert a single multibyte character sequence. itโs giving โone more time for the girlies in the back.โ ๐ญ
๐ RETURN VALUES ๐
The mbrtowc(), mbrtoc16(), and mbrtoc32() functions return:
0โ the nextnor fewer bytes represent the null wide character (L'\0'). ๐>0โ the nextnor fewer bytes represent a valid character, and these functions return the number of bytes used to complete the multibyte character. ๐ฅ(size_t)-1โ an encoding error has occurred. The nextnor fewer bytes do not contribute to a valid multibyte character. ๐จ(size_t)-2โ the nextncontribute to, but do not complete, a valid multibyte character sequence, and allnbytes have been processed. ๐ญ
The mbrtoc16() function also returns:
(size_t)-3โ the next character resulting from a previous call has been stored. No bytes from the input have been consumed. โจ
๐ ERRORS ๐
The mbrtowc(), mbrtoc16(), and mbrtoc32() functions will fail if:
[EILSEQ]โ an invalid multibyte sequence was detected.[EINVAL]โ the conversion state is invalid.
๐ SEE ALSO ๐
mbtowc(3), multibyte(3), setlocale(3), wcrtomb(3)
โญ STANDARDS โญ
The mbrtowc(), mbrtoc16(), and mbrtoc32() functions conform to ISO/IEC 9899:2011 (โISO C11โ). ๐ซถ
๐ xoxo, Debian โ May 21, 2013 โ MBRTOWC(3) ๐
๐ฆ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2002-2004 Tim J. Robbins
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms