c/string/multibyte/mbrtoc8

Converts a narrow multibyte character to UTF-8 encoding.

If is not a null pointer, inspects at most  bytes of the multibyte character string, beginning with the byte pointed to by  to determine the number of bytes necessary to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character in is complete and valid, converts it to UTF-8 and stores the first UTF-8 code unit in  (if  is not null).

If UTF-8 encoding of the multibyte character in consists of more than one UTF-8 code unit, then after the first call to this function,  is updated in such a way that the next call to  will write out the additional UTF-8 code units, without considering.

If is a null pointer, the values of  and  are ignored and the call is equivalent to.

If UTF-8 code unit produced is, the conversion state represents the initial shift state.

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

Return value
The first of the following that applies:
 * if the character converted from (and stored in  if non-null) was the null character
 * the number of bytes of the multibyte character successfully converted from
 * if the next UTF-8 code unit from a character whose encoding consists of multiple code units has now been written to . No bytes are processed from the input in this case.
 * if the next bytes constitute an incomplete, but so far valid, multibyte character. Nothing is written to.
 * if encoding error occurs. Nothing is written to, the value eilseq is stored in errno and the value of is unspecified.