Section: Linux Programmer's Manual (3)
Return to Main Contents
mbrtowc - convert a multibyte sequence to a wide character
size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
The main case for this function is when
is not NULL and
In this case, the
function inspects at most
bytes of the multibyte string starting at
extracts the next complete
multibyte character, converts it to a wide character and stores it at
It updates the shift state
If the converted wide
character is not L'\0' (the null wide character),
it returns the number of bytes that were consumed
If the converted wide character is L'\0', it resets the shift
to the initial state and returns 0.
bytes starting at
do not contain a complete multibyte
This can happen even if
if the multibyte string contains redundant shift
If the multibyte string starting at
contains an invalid multibyte
sequence before the next complete character,
In this case,
the effects on
A different case is when
is not NULL but
function behaves as above, except that it does not
store the converted wide character in memory.
A third case is when
In this case,
If the conversion state represented by
incomplete multibyte character conversion, the
in an undefined state.
in the initial state and returns 0.
In all of the above cases, if
is a NULL pointer, a static anonymous
state known only to the
function is used instead.
must be a valid
can be initialized to the initial state
by zeroing it, for example using
memset(&a, 0, sizeof(a));
function returns the number of bytes parsed from the
multibyte sequence starting at
if a non-L'\0' wide character
It returns 0, if a L'\0' wide character was recognized.
if an invalid multibyte sequence was
if it couldn't parse a complete multibyte
character, meaning that
should be increased.
Multithreading (see pthreads(7))
function is thread-safe with exceptions.
It is not thread-safe if called with a NULL ps parameter.
The behavior of
depends on the
category of the
This page is part of release 3.54 of the Linux
A description of the project,
and information about reporting bugs,
can be found at
- RETURN VALUE
- Multithreading (see pthreads(7))
- CONFORMING TO
- SEE ALSO
This document was created by
using the manual pages.
Time: 16:17:13 GMT, January 22, 2018