c16rtomb, c32rtomb Subroutine
Purpose
The c16rtomb and c32rtomb subroutines convert a 16-bit wide character (UTF-16) and a 32-bit wide character (UTF-32) to the corresponding multibyte character of the current locale.
Library
Standard C library (libc.a)
Syntax
Description
c16rtomb(buf, L'\0', ps)
If the value of the s parameter is not a null pointer, the c16rtomb subroutine determines the number of bytes needed to represent the multibyte character that corresponds to the wide character specified by the c16 parameter, including any shift sequences, and stores the multibyte character representation in an array, in which the first element is specified by the s parameter.
The value greater than the value of MB_CUR_MAX bytes is stored.
If the value of the c16 parameter is a null wide character, a null byte is stored, preceded by any shift sequence that is needed to restore the initial shift state and the resulting state is described is the initial conversion state.
c32rtomb(buf, L'\0', ps)
If the value of the s parameter is not a null pointer, the c32rtomb subroutine determines the number of bytes needed to represent the multibyte character that corresponds to the wide character specified by the c32 parameter, including any shift sequences, and stores the multibyte character representation in an array, in which the first element is specified by the s parameter.
The value greater than the value of MB_CUR_MAX bytes is stored. If the value of the c32 parameter is a null wide character, a null byte is stored, preceded by any shift sequence that is needed to restore the initial shift state and the resulting state is described is the initial conversion state.
Parameters
Item | Description |
---|---|
s | Specifies the first element of an array where the multibyte character representation is stored. |
c16, c32 | Represents the wide character sequence. |
ps | Specifies the state of the multibyte conversion. |
Example
- The mbstate_t pointer can be used as follows:
mbstate_t ss = 0;
int x = c16rtomb(out, in, &ss);
Return Values
The c16rtomb subroutine returns the number of bytes stored in an array object, including any shift sequences.
When the value of the c16 parameter is not a valid wide character, an encoding error occurs. The function stores the value of the EILSEQ macro in the errno variable and returns the (size_t)(-1). The conversion state is unspecified.
The c32rtomb subroutine returns the number of bytes stored in an array object, including any shift sequences.
When the value of the c32 parameter is not a valid wide character, an encoding error occurs. The function stores the value of the EILSEQ macro in the errno variable and returns (size_t)(-1). The conversion state is unspecified.
Error codes
The c16rtomb and c32rtomb subroutine is unsuccessful if the following error code is set.
Item | Description |
---|---|
EILSEQ | Indicates an invalid multibyte character sequence. |
Files
The uchar.h file defines standard macros, data types, and subroutines.