#include
int wctob(wint_t src);
wctob
attempts to convert the wide character src
into a 1-byte character, and return it. It
returns EOF
if src
is WEOF
or cannot be
converted.
#include
int wctomb(char *dst, wchar_t src);
#include
int wcrtomb(char *dst,
wchar_t src,
mbstate_t *mbs);
errno_t wcrtomb_s(size_t * retval,
char *dst,
rsize_t dstlen,
wchar_t src,
mbstate_t *mbs);
#include
size_t wcstombs(char *dst,
const wchar_t *src,
size_t n);
#define __STDC_WANT_LIB_EXT1__ 1
#include
errno_t wctomb_s(int *retval,
char *dst,
rsize_t dstlen,
wchar_t src);
These functions convert the wide character
src
into a multibyte character,
according to the current locale and a conversion state.
wcrtomb
and
wcrtomb_s
use an external conversion state
*mbs
.
wctomb
and
wctomb_s
each use their own internal
states.
wcrtomb
also has an internal state, which
is used if mbs
is null. Whichever
state is used, if src
is a null
character, the state is reset to the initial state.
If dst
is null,
wctomb
and
wctomb_s
indicate whether multibyte
encodings [in the current
locale?] are state-dependent with a non-zero
result.
wctomb
returns that result, while
wctomb_s
writes it into *retval
.
If dst
is null,
wcrtomb
and
wcrtomb_s
reset their conversion states.
wcrtomb
then returns the number of bytes
required for a shift sequence that would reset the
conversion state, while
wcrtomb_s
writes the number into
*retval
.
If dst
is not null, and the
wide character is valid and has a multibyte equivalent,
all functions write the equivalent bytes to dst
, including any shift sequence
corresponding to a change in conversion state.
wctomb
and
wcrtomb
return the number of bytes written,
while
wctomb_s
and
wcrtomb_s
write the number into
*retval
. No function writes more
than
MB_CUR_MAX
bytes to dst
for the current locale, and no more than
MB_LEN_MAX
for any supported
locale.
Additionally,
wcrtomb
and
wcrtomb_s
interpret non-null dst
as an array of dstlen
bytes. If that is not sufficient to
represent the character and any necessary preceding shift
sequences,
wcrtomb
returns -1
,
while
wcrtomb_s
sets *retval
to (size_t) -1
and returns
non-zero.
The null wide character is converted to any shift
sequences required to return to the initial state, plus a
null byte. This final null byte is not included in any
count of bytes written or returned.
If src
is not a valid wide
character/does not correspond to a valid multibyte
character,
wcrtomb
returns -1
,
wcrtomb
sets errno
to
EILSEQ
and returns (size_t) -1
,
wctomb_s
sets *retval
to -1
and
returns non-zero, and
wcrtomb_s
sets *retval
to (size_t) -1
and returns
non-zero.
|
wctomb |
wcrtomb |
wctomb_s |
wcrtomb_s |
Conversion state |
Internal |
*mbs , or internal if
mbs is null |
*mbs |
Meaning of byte count when dst is null |
Non-zero indicates state-dependence |
Number of bytes required to return to initial
conversion state |
Non-zero indicates state-dependence |
Number of bytes required to return to initial
conversion state |
Provision of byte count |
Return value |
*retval |
Other effects if dst is
null |
None |
Conversion state reset |
None |
Conversion state reset |
Invalid wide character |
Return -1 |
Set errno to
EILSEQ and return (size_t) -1 |
Set *retval to
-1 and return non-zero |
Set *retval to
(size_t) -1 and
return non-zero |
Buffer overflow |
Not detected |
Return non-zero |
Set dst[0] to zero if
dstlen greater than 0 and less
than RSIZE_MAX , set
*retval to (size_t) -1 if
retval not null, and return
non-zero |