mbstowcs, mbstowcs_s
From cppreference.com
| Defined in header <stdlib.h>
|
||
| (1) | ||
| (until C99) | ||
| (since C99) | ||
| errno_t mbstowcs_s(size_t *restrict retval, wchar_t *restrict dst, rsize_t dstsz, const char *restrict src, rsize_t len); |
(2) | (since C11) |
1) Converts a multibyte character string from the array whose first element is pointed to by
src to its wide character representation. Converted characters are stored in the successive elements of the array pointed to by dst. No more than len wide characters are written to the destination array. Each character is converted as if by a call to mbtowc, except that the mbtowc conversion state is unaffected. The conversion stops if:
* The multibyte null character was converted and stored.
* An invalid (in the current C locale) multibyte character was encountered.
* The next wide character to be stored would exceed
len. If
src and dst overlap, the behavior is undefined2) Same as (1), except that
* the function returns its result as an out-parameter
retval * if no null character was written to
dst after len wide characters were written, then L'\0' is stored in dst[len], which means len+1 total wide characters are written * if
dst is a null pointer, the number of wide characters that would be produced is stored in *retval * the function clobbers the destination array from the terminating null and until
dstsz * If
src and dst overlap, the behavior is unspecified. * the following errors are detected at runtime and call the currently installed constraint handler function:
-
retvalorsrcis a null pointer -
dstszorlenis greater than RSIZE_MAX/sizeof(wchar_t) (unlessdstis null) -
dstszis not zero (unlessdstis null) - There is no null character in the first
dstszmultibyte characters in thesrcarray andlenis greater thandstsz(unlessdstis null)
-
- As with all bounds-checked functions,
mbstowcs_sis only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <stdlib.h>.
Contents |
[edit] Notes
In most implementations, mbstowcs updates a global static object of type mbstate_t as it processes through the string, and cannot be called simultaneously by two threads,