Node:Non-reentrant String Conversion, Next:Shift State, Previous:Non-reentrant Character Conversion, Up:Non-reentrant Conversion
For convenience the ISO C90 standard also defines functions to convert entire strings instead of single characters. These functions suffer from the same problems as their reentrant counterparts from Amendment 1 to ISO C90; see Converting Strings.
size_t mbstowcs (wchar_t *wstring, const char *string, size_t size) | Function |
The mbstowcs ("multibyte string to wide character string")
function converts the null-terminated string of multibyte characters
string to an array of wide character codes, storing not more than
size wide characters into the array beginning at wstring.
The terminating null character counts towards the size, so if size
is less than the actual number of wide characters resulting from
string, no terminating null character is stored.
The conversion of characters from string begins in the initial shift state. If an invalid multibyte character sequence is found, the Here is an example showing how to convert a string of multibyte
characters, allocating enough space for the result.
wchar_t * mbstowcs_alloc (const char *string) { size_t size = strlen (string) + 1; wchar_t *buf = xmalloc (size * sizeof (wchar_t)); size = mbstowcs (buf, string, size); if (size == (size_t) -1) return NULL; buf = xrealloc (buf, (size + 1) * sizeof (wchar_t)); return buf; } |
size_t wcstombs (char *string, const wchar_t *wstring, size_t size) | Function |
The wcstombs ("wide character string to multibyte string")
function converts the null-terminated wide character array wstring
into a string containing multibyte characters, storing not more than
size bytes starting at string, followed by a terminating
null character if there is room. The conversion of characters begins in
the initial shift state.
The terminating null character counts towards the size, so if size is less than or equal to the number of bytes needed in wstring, no terminating null character is stored. If a code that does not correspond to a valid multibyte character is
found, the |