— convert a wide character to a
wcrtomb(const char * restrict s,
wchar_t wc, mbstate_t * restrict
c32rtomb(char * restrict s,
char32_t wc, mbstate_t * restrict
convert the wide character wc to the corresponding
multibyte character, and store up to
bytes in the array pointed to by s if
s is not a
NULL pointer. The
interpretation of wc is implementation-defined. On
OpenBSD, wchar_t and
char32_t are of the same width and both are always
interpreted as Unicode codepoints.
The output encoding that
use in s is determined by the
LC_CTYPE category of the current locale.
OpenBSD only supports UTF-8 and ASCII output, and
these functions are only useful for UTF-8.
The following arguments cause special processing:
- wc == 0
- A NUL byte is stored to *s and the state object pointed to by mbs is reset to the initial state. On operating systems other than OpenBSD that support state-dependent multibyte encodings, a special byte sequence (“shift sequence”) is written before the NUL byte to return to the initial state if that is required by the output encoding and by the current output encoding state.
- mbs ==
c32rtomb() each use their own internal state object instead of the mbs argument. Both internal state objects are initialized at startup time of the program, and no other libc function ever changes either of them.
- s ==
- The object pointed to by mbs, or the internal object
if mbs is a
NULLpointer, is reset to the initial state, wc is ignored, and 1 is returned.
c32rtomb() return the number of bytes (including any
shift sequences) which are stored in the array pointed to by
s, or 1 if s is
NULL. If wc is not a valid
wide character or if it cannot be represented in the multibyte encoding
LC_CTYPE, both functions return
(size_t)-1 and set errno to
indicate the error.
c32rtomb() cause an error in the following
- wc is not a valid wide character or cannot be
- mbs points to an invalid or uninitialized mbstate_t object.
mbrtowc(3), setlocale(3), wctomb(3)
wcrtomb() conforms to
ISO/IEC 9899/AMD1:1995 (“ISO C90, Amendment
1”). The restrict qualifier was added at
c32rtomb() conforms to
wcrtomb() has been available since
OpenBSD 3.8 and has provided support for UTF-8 since
c32rtomb() has been available since