f non- Dv NULL and .Fa s points to a valid character. This function may inspect at most n bytes of the array beginning from .Fa s .
p In state-dependent encodings, .Fa s may point to the special sequence bytes to change the shift-state. Although such sequence bytes correspond to no individual wide-character code, .Fn mbtowc changes its own state by the sequence bytes and treats them as if they are a part of the subsequence multibyte character.
p Unlike .Xr mbrtowc 3 , the first .Fa n bytes pointed to by .Fa s need to form an entire multibyte character. Otherwise, this function causes an error.
p Calling any other functions in .Lb libc never changes the internal state of .Fn mbtowc , except for calling .Xr setlocale 3 with changing the .Dv LC_CTYPE category of the current locale. Such .Xr setlocale 3 call causes the internal state of this function to be indeterminate.
p The behaviour of .Fn mbtowc is affected by the .Dv LC_CTYPE category of the current locale.
p
There are special cases:
l -tag -width 012345678901 t s == NULL .Fn mbtowc
initializes its own internal state to an initial state, and
determines whether the current encoding is state-dependent.
This function returns 0 if the encoding is state-independent,
otherwise non-zero.
In this case,
.Fa pwc
is completely ignored.
t pwc == NULL .Fn mbtowc
executes the conversion as if
.Fa pwc
is non-NULL, but a result of the conversion is discarded.
t n == 0 In this case,
the first
.Fa n
bytes of the array pointed to by
.Fa s
never form a complete character.
Thus, the
.Fn mbtowc
always fails.
.El
----------------------------------------------------------------------
.Sh RETURN VALUES
Normally, the
.Fn mbtowc
returns:
l -tag -width 012345678901 t 0 .Fa s
points to a nul byte
q Sq \e0 . t positive Number of bytes for the valid multibyte character pointed to by .Fa s . There are no cases that the value returned is greater than the value of the .Dv MB_CUR_MAX macro. t -1 .Fa s points to an invalid or an incomplete multibyte character. The .Fn mbtowc also sets .Va errno to indicate the error. .El
p
When
.Fa s
is equal to
.Dv NULL ,
.Fn mbtowc
returns:
l -tag -width 0123456789 t 0 The current encoding is state-independent.
t non-zero The current encoding is state-dependent.
.El
----------------------------------------------------------------------
.Sh ERRORS
.Fn mbtowc
may cause an error in the following case:
l -tag -width Er t Bq Er EILSEQ .Fa s
points to an invalid or incomplete multibyte character.
.El
----------------------------------------------------------------------
.Sh SEE ALSO
.Xr mblen 3 ,
.Xr mbrtowc 3 ,
.Xr setlocale 3
----------------------------------------------------------------------
.Sh STANDARDS
The
.Fn mbtowc
function conforms to
.St -ansiC .
The restrict qualifier is added at
.St -isoC-99 .