c/string/multibyte/c16rtomb

Converts a single code point from its variable-length 16-bit wide character representation (typically, UTF-16) to its narrow multibyte character representation.

If is not a null pointer and  is the last 16-bit code unit in a valid variable-length encoding of a code point, the function determines the number of bytes necessary to store the multibyte character representation of that code point (including any shift sequences, and taking into account the current multibyte conversion state ), and stores the multibyte character representation in the character array whose first element is pointed to by, updating  as necessary. At most bytes can be written by this function.

If is a null pointer, the call is equivalent to  for some internal buffer.

If is the null wide character, a null byte is stored, preceded by any shift sequence necessary to restore the initial shift state and the conversion state parameter  is updated to represent the initial shift state.

If is not the final code unit in a 16-bit representation of a wide character, it does not write to the array pointed to by, only  is updated.

If the macro is defined, the 16-bit encoding used by this function is UTF-16; otherwise, it is implementation-defined. In any case, the multibyte character encoding used by this function is specified by the currently active C locale.

Return value
On success, returns the number of bytes (including any shift sequences) written to the character array whose first element is pointed to by. This value may be, e.g. when processing the leading units in a multi--unit sequence (occurs when processing the leading surrogate in a surrogate pair of UTF-16).

On failure (if is not a valid 16-bit code unit), returns, stores eilseq in errno, and leaves  in unspecified state.