7.20.7.2 The mbtowc function

Synopsis

1

#include <stdlib.h>
int mbtowc(wchar_t * restrict pwc,
     const char * restrict s,
     size_t n);

Description

2

If s is not a null pointer, the mbtowc function inspects at most n bytes beginning with the byte pointed to by s to determine the number of bytes needed to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character is complete and valid, it determines the value of the corresponding wide character and then, if pwc is not a null pointer, stores that value in the object pointed to by pwc. If the corresponding wide character is the null wide character, the function is left in the initial conversion state.

3

The implementation shall behave as if no library function calls the mbtowc function.

Returns

4

If s is a null pointer, the mbtowc function returns a nonzero or zero value, if multibyte character encodings, respectively, do or do not have state-dependent encodings. If s is not a null pointer, the mbtowc function either returns 0 (if s points to the null character), or returns the number of bytes that are contained in the converted multibyte character (if the next n or fewer bytes form a valid multibyte character), or returns -1 (if they do not form a valid multibyte character).

5

In no case will the value returned be greater than n or the value of the MB_CUR_MAX macro.