c8rtomb

From cppreference.com
< c‎ | string‎ | multibyte
Defined in header <uchar.h>
size_t c8rtomb( char * restrict s, char8_t c8, mbstate_t * restrict ps ) ;
(since C23)

Converts a single code point from UTF-8 to a narrow multibyte character representation.

If s is not a null pointer and c8 *ps), and stores the multibyte character representation in the character array whose first element is pointed to by s, updating *ps as necessary. At most MB_CUR_MAX

If c8 is not the final UTF-8 code unit in a representation of a code point, the function does not write to the array pointed to by s, only *ps

If s is a null pointer, the call is equivalent to c8rtomb(buf, u8'\0', ps) for some internal buffer buf

If c8 is the null character u8'\0' , a null byte is stored, preceded by any shift sequence necessary to restore the initial shift state and the conversion state parameter *ps

The multibyte encoding used by this function is specified by the currently active C locale.

Parameters

s - pointer to narrow character array where the multibyte character will be stored
c8 - the UTF-8 code unit to convert
ps - pointer to the conversion state object used when interpreting the multibyte string

Return value

The number of bytes stored in the array object (including any shift sequences). This may be zero when c8

If c8 is invalid (does not contribute to a sequence of char8_t corresponding to a valid multibyte character), the value of the macro EILSEQ is stored in errno, (size_t)-1

Notes

Calls to c8rtomb with a null pointer argument for s may introduce a data race with other calls to c8rtomb with a null pointer argument for s

Example

See also

(C23)
converts a narrow multibyte character to UTF-8 encoding
(function)
C++ documentation for c8rtomb