3 <<wcstombs>>---minimal wide char string to multibyte string converter
10 size_t wcstombs(char *restrict <[s]>, const wchar_t *restrict <[pwc]>, size_t <[n]>);
13 When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
14 implementation of <<wcstombs>>. In this case,
15 all wide-characters are expected to represent single bytes and so
16 are converted simply by casting to char.
18 When _MB_CAPABLE is defined, this routine calls <<_wcstombs_r>> to perform
19 the conversion, passing a state variable to allow state dependent
20 decoding. The result is based on the locale setting which may
21 be restricted to a defined set of locales.
24 This implementation of <<wcstombs>> returns <<0>> if
25 <[s]> is <<NULL>> or is the empty string;
26 it returns <<-1>> if _MB_CAPABLE and one of the
27 wide-char characters does not represent a valid multi-byte character;
28 otherwise it returns the minimum of: <<n>> or the
29 number of bytes that are transferred to <<s>>, not including the
32 If the return value is -1, the state of the <<pwc>> string is
33 indeterminate. If the input has a length of 0, the output
34 string will be modified to contain a wchar_t nul terminator if
38 <<wcstombs>> is required in the ANSI C standard. However, the precise
39 effects vary with the locale.
41 <<wcstombs>> requires no supporting OS subroutines.
51 wcstombs (char *__restrict s
,
52 const wchar_t *__restrict pwcs
,
59 return _wcstombs_r (_REENT
, s
, pwcs
, n
, &state
);
60 #else /* not _MB_CAPABLE */
65 if ((*s
++ = (char) *pwcs
++) == 0)
72 #endif /* not _MB_CAPABLE */
75 #endif /* !_REENT_ONLY */