MBSTOWCS(3) BSD Library Functions Manual MBSTOWCS(3)NAME
mbstowcs -- converts a multibyte character string to a wide-character string
Standard C Library (libc, -lc)
mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
mbstowcs() converts a nul-terminated multibyte character string pointed to by s to the corresponding wide-character string and stores it in
the array pointed to by pwcs. This function may modify the first at most n elements of 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.
For state-dependent encoding, mbstowcs() implies the multibyte character string pointed to by s always begins 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).
0 or positive
Number of elements stored in the array pointed to by pwcs. There are no cases that the value returned is greater than n
(unless pwcs is a null pointer) or the value of the MB_CUR_MAX macro. If the return value is equal to n, the string pointed to
by pwcs will not be nul-terminated.
(size_t)-1 s points to a string containing an invalid or incomplete multibyte character. The mbstowcs() also sets errno to indicate the
mbstowcs() may cause an error in the following case:
[EILSEQ] s points to a string containing an invalid or incomplete multibyte character.
SEE ALSO mbtowc(3), setlocale(3), wcstombs(3)STANDARDS
The mbstowcs() function conforms to ANSI X3.159-1989 (``ANSI C89''). The restrict qualifier is added at ISO/IEC 9899:1999 (``ISO C99'').
BSD March 16, 2011 BSD
Check Out this Related Man Page
mbstowcs(3) Library Functions Manual mbstowcs(3)NAME
mbstowcs, mbsrtowcs - Converts a multibyte character string to a wide-character string
Standard C Library (libc)
const char *s,
const char **s,
mbstate_t *ps );
Interfaces documented on this reference page conform to industry standards as follows:
mbstowcs(), mbsrtowcs(): XSH5.0
Refer to the standards(5) reference page for more information about industry standards and associated tags.
Points to the array where the result of the conversion is stored. Points or indirectly points to the multibyte-character string to be con-
verted. Specifies the number of wide characters in the destination array. Points to an mbstate_t structure containing the conversion
state of the data in s.
The mbstowcs() function converts a multibyte-character string into a wide-character string, which is stored at a specified location. The
function does not examine or convert any characters that follow a null byte, which is converted and stored as a wide-character code with
value zero. The function does not store more than n wide characters in pwcs. When operating on overlapping strings, the behavior of this
function is undefined.
Behavior of the mbstowcs() function is affected by the LC_CTYPE category of the current locale. In locales that use shift-state encoding,
the array pointed to by the s parameter begins in the initial shift state.
The mbsrtowcs() function is a restartable version of mbstowcs(). Restartable conversion functions obtain and store the conversion state in
an mbstate_t structure that can be read and changed by subsequent calls to the same or other restartable conversion functions.
[Tru64 UNIX] The mbsrtowcs() and other restartable versions of conversion functions are functional only when used with locales that sup-
port shift-state encoding. Currently, the operating system does not provide any locales that support shift-state encoding, so the
mbstowcs() and mbsrtowcs() functions do not differ in terms of run-time behavior.
When the mbstowcs() and mbsrtowcs() functions encounter an invalid multibyte character during conversion, they return a value of -1 cast to
size_t and set errno to indicate the error. Otherwise: The mbstowcs() function returns the number of characters stored in the output array
(or required if pwcs is null), not including a terminating null wide character, if any. When the return value is n, the output array is not
null-terminated. The mbsrtowcs() function returns the number of characters stored in the output array, not including a terminating null
wide character, if any.
If the following condition occurs, the mbstowcs() and mbsrtowcs() functions set errno to the corresponding value: The s parameter contains
an invalid multibyte character.
Functions: btowc(3), mblen(3), mbsinit(3), mbtowc(3), wcstombs(3), wcslen(3), wctob(3), wctomb(3) delim off