iconv(3) Library Functions Manual iconv(3) iconv - LIBRARY Standard C library (libc, -lc) #include size_t iconv(iconv_t cd, char **restrict inbuf, size_t *restrict inbytesleft, char **restrict outbuf, size_t *restrict outbytesleft); iconv() . cd , iconv_open(3); , iconv() . inbuf , ; inbytesleft . outbuf , ; outbytesleft . inbuf NULL *inbuf NULL. iconv() *inbuf, *outbuf. *inbytesleft, *inbuf. *outbytesleft, *outbuf. The iconv() function converts one multibyte character at a time, and for each character conversion it increments *inbuf and decrements *inbytesleft by the number of converted input bytes, it increments *outbuf and decrements *outbytesleft by the number of converted output bytes, and it updates the conversion state contained in cd. If the character encoding of the input is stateful, the iconv() function can also convert a sequence of input bytes to an update to the conversion state without producing any output bytes; such input is called a shift sequence. The conversion can stop for five reasons: o . errno EILSEQ (size_t) -1. *inbuf . o A multibyte sequence is encountered that is valid but that cannot be translated to the character encoding of the output. This condition depends on the implementation and on the conversion descriptor. In the GNU C library and GNU libiconv, if cd was created without the suffix //TRANSLIT or //IGNORE, the conversion is strict: lossy conversions produce this condition. If the suffix //TRANSLIT was specified, transliteration can avoid this condition in some cases. In the musl C library, this condition cannot occur because a conversion to '*' is used as a fallback. In the FreeBSD, NetBSD, and Solaris implementations of iconv(), this condition cannot occur either, because a conversion to '?' is used as a fallback. When this condition is met, iconv() sets errno to EILSEQ and returns (size_t) -1. *inbuf is left pointing to the beginning of the unconvertible multibyte sequence. o , *inbytesleft . iconv() , . o . errno EINVAL (size_t) -1. *inbuf . o . errno E2BIG (size_t) -1. , inbuf NULL *inbuf NULL, outbuf NULL *outbuf NULL. iconv() cd *outbuf. *outbytesleft, *outbuf. , errno E2BIG (size_t) -1. *outbuf *outbytesleft . , inbuf NULL *inbuf NULL, outbuf NULL *outbuf NULL, iconv() cd . The iconv() function returns the number of characters converted in a nonreversible way during this call; reversible conversions are not counted. In case of error, iconv() returns (size_t) -1 and sets errno to indicate the error. : E2BIG *outbuf. EILSEQ . EINVAL . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |iconv() | | MT-Safe race:cd | +----------------------------+----------------------------------------------------------+--------------------------+ iconv() cd - . POSIX.1-2008. glibc 2.1. POSIX.1-2001. iconv() inbuf *inbuf NULL ( ). inbuf outbuf char **, , , , : . . iconv() , , , . , . . iconv_close(3), iconv_open(3), iconvconfig(8) Azamat Hackimov , Dmitriy S. Seregin , Yuri Kozlov ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . iconv(3)