NAME
c16rtomb c32rtomb
— convert a Unicode character code to a character
(restartable)
SYNOPSIS
#include
<uchar.h>
size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps); size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps);
DESCRIPTION
[CX] The functionality described on this reference page is aligned with the ISO C standard. Any conflict between the requirements described here and the ISO C standard is unintentional. This volume of POSIX.1-2024 defers to the ISO C standard.
If s is a null pointer, the
c16rtomb () function shall be equivalent to the
call:
c16rtomb(buf, L'\0', ps)
where buf is an internal buffer.
If s is not a null pointer, the
c16rtomb () function shall determine the number of
bytes needed to represent the character that corresponds to the wide
character given by c16 (including any shift sequences),
and store the resulting bytes in the array whose first element is pointed to
by s. At most {MB_CUR_MAX} bytes shall be stored. If
c16 is a null wide character, a null byte shall be stored,
preceded by any shift sequence needed to restore the initial shift state;
the resulting state described shall be the initial conversion state.
If ps is a null pointer, the
c16rtomb () function shall use its own internal
mbstate_t object, which shall be initialized at program
start-up to the initial conversion state. Otherwise, the
mbstate_t object pointed to by ps shall
be used to completely describe the current conversion state of the
associated character sequence.
The behavior of this function is affected by the LC_CTYPE category of the current locale.
The mbrtoc16(3) function shall not change the setting of errno if successful.
The c32rtomb () function shall
behave the same way as c16rtomb () except that the
second parameter shall be an object of type
char32_t instead
of
char16_t.
References to c16 in the above description shall apply as
if they were c32 when they are being read as describing
c32rtomb ().
If called with a null ps argument, the
c16rtomb () function need not be thread-safe;
however, such calls shall avoid data races with calls to
c16rtomb () with a non-null argument and with calls
to all other functions.
If called with a null ps argument, the c32rtomb () function need not be thread-safe; however, such calls shall avoid data races with calls to c32rtomb () with a non-null argument and with calls to all other functions.
The implementation shall behave as if no function defined in this
volume of POSIX.1-2024 calls c16rtomb () or
c32rtomb () with a null pointer for
ps.
RETURN VALUE
These functions shall return the number of bytes stored in the array object (including any shift sequences). When c16 or c32 is not a valid wide character, an encoding error shall occur. In this case, the function shall store the value of the macro [EILSEQ] in errno and shall return ( size_t) -1; the conversion state is unspecified.
ERRORS
These functions shall fail if:
- [EILSEQ]
- An invalid wide-character code is detected.
These functions may fail if:
- [EINVAL]
- [CX] ps points to an object that contains an invalid conversion state.
EXAMPLES
None.
APPLICATION USAGE
None.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
XBD <uchar.h>
CHANGE HISTORY
First released in Issue 8. Included for alignment with the ISO/IEC 9899:2018 standard.