Using the iconv_open subroutine
This section will illustrate how to use the iconv_open subroutine in different situations.
The following examples illustrate how to use the iconv_open subroutine in different situations:
- When the sender and receiver use the same code sets, and if the
protocol allows 8-bit data, you can send data without converting it.
If the protocol allows only 7-bit data, do the following:
Sender: cd = iconv_open("uucode", nl_langinfo(CODESET)); Receiver: cd = iconv_open(nl_langinfo(CODESET), "uucode");
- When the sender and receiver use different code sets, and if the
protocol allows 8-bit data and the receiver's code set is unknown,
do the following
Sender: cd = iconv_open("fold8", nl_langinfo(CODESET)); Receiver: cd = iconv_open(nl_langinfo(CODESET),"fold8" );
If the protocol allows only 7-bit data, do the following:Sender: cd = iconv_open("fold7", nl_langinfo(CODESET)); Receiver: cd = iconv_open(nl_langinfo(CODESET), "fold7" );
iconv/FromCodeSet_ToCodeSet
The FromCodeSet string represents the sender's code set, and the ToCodeSet string represents the receiver's code set. The underscore character separates the two strings.
iconv/FromCodeSet_ToCodeSet__64.
The iconv library automatically chooses whether to load the standard converter object or the 64-bit converter object. If the iconv_open subroutine does not find the converter, it uses the from,to pair to search for a file that defines a table-driven conversion. The file contains a conversion table created by the genxlt command.
The iconvTable converter uses the LOCPATH environment variable to search for a file whose name is in the following form:
iconvTable/FromCodeSet_ToCodeSet
If the converter is found, it performs a load operation and is initialized. The converter descriptor, iconv_t, is returned in its initial state.