3 <<mbtowc>>---minimal multibyte to wide char converter
10 int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
13 When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
14 implementation of <<mbtowc>>. In this case,
15 only ``multi-byte character sequences'' recognized are single bytes,
16 and they are ``converted'' to themselves.
17 Each call to <<mbtowc>> copies one character from <<*<[s]>>> to
18 <<*<[pwc]>>>, unless <[s]> is a null pointer. The argument n
21 When _MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
22 the conversion, passing a state variable to allow state dependent
23 decoding. The result is based on the locale setting which may
24 be restricted to a defined set of locales.
27 This implementation of <<mbtowc>> returns <<0>> if
28 <[s]> is <<NULL>> or is the empty string;
29 it returns <<1>> if not _MB_CAPABLE or
30 the character is a single-byte character; it returns <<-1>>
31 if n is <<0>> or the multi-byte character is invalid;
32 otherwise it returns the number of bytes in the multibyte character.
33 If the return value is -1, no changes are made to the <<pwc>>
34 output string. If the input is the empty string, a wchar_t nul
35 is placed in the output string and 0 is returned. If the input
36 has a length of 0, no changes are made to the <<pwc>> output string.
39 <<mbtowc>> is required in the ANSI C standard. However, the precise
40 effects vary with the locale.
42 <<mbtowc>> requires no supporting OS subroutines.
52 #ifdef _REENT_THREAD_LOCAL
53 _Thread_local _mbstate_t _tls_mbtowc_state
;
57 mbtowc (wchar_t *__restrict pwc
,
58 const char *__restrict s
,
63 struct _reent
*reent
= _REENT
;
66 _REENT_CHECK_MISC(reent
);
67 ps
= &(_REENT_MBTOWC_STATE(reent
));
69 retval
= __MBTOWC (reent
, pwc
, s
, n
, ps
);
77 #else /* not _MB_CAPABLE */
85 #endif /* not _MB_CAPABLE */
88 #endif /* !_REENT_ONLY */