p In state-dependent encodings, .Fa s may point the special sequence bytes to change the shift-state. Although such sequence bytes corresponds to no individual wide-character code, the .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 by .Fa s need to form an entire multibyte character. Otherwise, this function causes an error.
p Calling any other functions in the .Lb libc never change the internal state of the .Fn mbtowc , except for calling .Xr setlocale 3 with changing 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 the .Fn mbtowc is affected by 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 by
.Fa s
never form a complete character.
Thus, the
.Fn mbtowc
always fails.
.El
----------------------------------------------------------------------
.Sh RETURN VALUES
In the usual cases, the
.Fn mbtowc
returns:
l -tag -width 012345678901 t 0 .Fa s
points a null byte (\'\\0\').
t positive number of bytes for the valid multibyte character pointed by
.Fa s .
There is no cases that the value returned is greater than
the value of MB_CUR_MAX macro.
t -1 .Fa s
points an invalid or an incomplete multibyte character.
The
.Fn mbtowc
also sets errno to indicate the error.
.El
p
In the case that
.Fa s
is equal to NULL, the
.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
The
.Fn mbtowc
may causes an error in the following case:
l -tag -width Er t Bq Er EILSEQ .Fa s
points 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 .