6 /* Do not include the above headers in the example.
9 mbstouwcs (const char *s
)
11 /* Include the null terminator in the conversion. */
12 size_t len
= strlen (s
) + 1;
13 wchar_t *result
= reallocarray (NULL
, len
, sizeof (wchar_t));
17 wchar_t *wcp
= result
;
19 memset (&state
, '\0', sizeof (state
));
24 size_t nbytes
= mbrtowc (&wc
, s
, len
, &state
);
27 /* Terminate the result string. */
31 else if (nbytes
== (size_t) -2)
33 /* Truncated input string. */
38 else if (nbytes
== (size_t) -1)
40 /* Some other error (including EILSEQ). */
46 /* A character was converted. */
47 *wcp
++ = towupper (wc
);