### 15.2 Introduction to iconv ¶

The iconv library is intended to convert characters from one encoding to another. It implements iconv(), iconv_open() and iconv_close() calls, which are defined by the Single Unix Specification.

In addition to these user-level interfaces, the iconv library also has several useful interfaces which are needed to support coding capabilities of the Newlib Locale infrastructure. Since Locale support also needs to convert various character sets to and from the wide characters set, the iconv library shares it’s capabilities with the Newlib Locale subsystem. Moreover, the iconv library supports several features which are only needed for the Locale infrastructure (for example, the MB_CUR_MAX value).

The Newlib iconv library was created using concepts from another iconv library implemented by Konstantin Chuguev (ver 2.0). The Newlib iconv library was rewritten from scratch and contains a lot of improvements with respect to the original iconv library.

Terms like encoding or character set aren’t well defined and are often used with various meanings. The following are the definitions of terms which are used in this documentation as well as in the iconv library implementation:

- encoding - a machine representation of characters by means of bits;
- Character Set or Charset - just a collection of characters, i.e. the encoding is the machine representation of the character set;
- CCS (Coded Character Set) - a mapping from an character set to a set of integers character codes;
- CES (Character Encoding Scheme) - a mapping from a set of character codes to a sequence of bytes;

Users usually deal with encodings, for example, KOI8-R, Unicode, UTF-8, ASCII, etc. Encodings are formed by the following chain of steps:

1. User has a set of characters which are specific to his or her language (character set).
2. Each character from this set is uniquely numbered, resulting in an CCS.
3. Each number from the CCS is converted to a sequence of bits or bytes by means of a CES and form some encoding. Thus, CES may be considered as a function of CCS which produces some encoding. Note, that CES may be applied to more than one CCS.

Thus, an encoding may be considered as one or more CCS + CES.

Sometimes, there is no CES and in such cases encoding is equivalent to CCS, e.g. KOI8-R or ASCII.

An example of a more complicated encoding is UTF-8 which is the UCS (or Unicode) CCS plus the UTF-8 CES.

The following is a brief list of iconv library features:

- Generic architecture;
- Locale infrastructure support;
- Automatic generation of the program code which handles CES/CCS/Encoding/Names/Aliases dependencies;
- The ability to choose size- or speed-optimazed configuration;
- The ability to exclude a lot of unneeded code and data from the linking step.