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" );
The iconv_open subroutine uses the LOCPATH environment variable to search for a converter whose name is in the following form:
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.

Note: All setuid and setgid programs ignore the LOCPATH environment variable.
Because the iconv converter is a loadable object module, a different object is required when running in the 64-bit environment. In the 64-bit environment, the iconv_open routine uses the LOCPATH environment variable to search for a converter whose name is in the following form:
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.