MBSTOWCS(3)

NAME
mbstowcs, mbstowcs_l - convert a multibyte character string to a wide-character string

SYNOPSIS
#include <stdlib.h>
size_t
mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
#include <xlocale.h>
mbstowcs_l(wchar_t * restrict pwcs, const char * restrict s, size_t n, locale_t l);

DESCRIPTION
mbstowcs() convert a null-terminated multibyte character string pointed to by s to the corresponding wide-character string and store up to n wide characters in the array pointed to by pwcs. Each character will be converted as if mbtowc(3) is continuously called, except the internal state of mbtowc(3) will not be affected.

The funcion mbstowcs() uses the current locale, while mbstowcs_l() uses the locale provided, see xlocale(3)

For state-dependent encoding, mbstowcs() implies the multibyte character string pointed to by s always begin with an initial state.

These are the special cases:

pwcs == NULL
    mbstowcs() returns the number of elements to store the whole wide-character string corresponding to the multibyte character string pointed to by s. In this case, n is ignored.

s == NULL
    Undefined (may cause the program to crash).

RETURN VALUES
mbstowcs() and mbstowcs_l() return:

0 or positive
    The value returned is the number of elements stored in the array pointed to by pwcs, except for a terminating null wide character (if any). If pwcs is not null and the value returned is equal to n, the wide-character string pointed to by pwcs is not null terminated. If pwcs is a null pointer, the value returned is the number of elements to contain the whole string converted, except for a terminating null wide character.

(size_t)-1
    The array indirectly pointed to by s contains a byte sequence forming invalid character. In this case, mbstowcs() sets errno to indicate the error.

ERRORS
mbstowcs() and mbstowcs_l() may cause an error in the following cases:

[EILSEQ]
    s points to the string containing invalid or incomplete multibyte character.

SEE ALSO
mbtowc(3), setlocale(3), xlocale(3)

STANDARDS
The mbstowcs() function conforms to ansiC. The restrict qualifier is added at ISO/IEC 9899/199 (“ISO C99”).