1ICONV(3) Linux Programmer's Manual ICONV(3)
2
3
4
6 iconv - perform character set conversion
7
9 #include <iconv.h>
10
11 size_t iconv(iconv_t cd,
12 char **inbuf, size_t *inbytesleft,
13 char **outbuf, size_t *outbytesleft);
14
16 The argument cd must be a conversion descriptor created using the func‐
17 tion iconv_open(3).
18
19 The main case is when inbuf is not NULL and *inbuf is not NULL. In
20 this case, the iconv() function converts the multibyte sequence start‐
21 ing at *inbuf to a multibyte sequence starting at *outbuf. At most
22 *inbytesleft bytes, starting at *inbuf, will be read. At most *out‐
23 bytesleft bytes, starting at *outbuf, will be written.
24
25 The iconv() function converts one multibyte character at a time, and
26 for each character conversion it increments *inbuf and decrements
27 *inbytesleft by the number of converted input bytes, it increments
28 *outbuf and decrements *outbytesleft by the number of converted output
29 bytes, and it updates the conversion state contained in cd. If the
30 character encoding of the input is stateful, the iconv() function can
31 also convert a sequence of input bytes to an update to the conversion
32 state without producing any output bytes; such input is called a shift
33 sequence. The conversion can stop for four reasons:
34
35 1. An invalid multibyte sequence is encountered in the input. In this
36 case it sets errno to EILSEQ and returns (size_t) -1. *inbuf is left
37 pointing to the beginning of the invalid multibyte sequence.
38
39 2. The input byte sequence has been entirely converted, that is,
40 *inbytesleft has gone down to 0. In this case iconv() returns the num‐
41 ber of nonreversible conversions performed during this call.
42
43 3. An incomplete multibyte sequence is encountered in the input, and
44 the input byte sequence terminates after it. In this case it sets
45 errno to EINVAL and returns (size_t) -1. *inbuf is left pointing to
46 the beginning of the incomplete multibyte sequence.
47
48 4. The output buffer has no more room for the next converted character.
49 In this case it sets errno to E2BIG and returns (size_t) -1.
50
51 A different case is when inbuf is NULL or *inbuf is NULL, but outbuf is
52 not NULL and *outbuf is not NULL. In this case, the iconv() function
53 attempts to set cd's conversion state to the initial state and store a
54 corresponding shift sequence at *outbuf. At most *outbytesleft bytes,
55 starting at *outbuf, will be written. If the output buffer has no more
56 room for this reset sequence, it sets errno to E2BIG and returns
57 (size_t) -1. Otherwise it increments *outbuf and decrements *out‐
58 bytesleft by the number of bytes written.
59
60 A third case is when inbuf is NULL or *inbuf is NULL, and outbuf is
61 NULL or *outbuf is NULL. In this case, the iconv() function sets cd's
62 conversion state to the initial state.
63
65 The iconv() function returns the number of characters converted in a
66 nonreversible way during this call; reversible conversions are not
67 counted. In case of error, it sets errno and returns (size_t) -1.
68
70 The following errors can occur, among others:
71
72 E2BIG There is not sufficient room at *outbuf.
73
74 EILSEQ An invalid multibyte sequence has been encountered in the input.
75
76 EINVAL An incomplete multibyte sequence has been encountered in the
77 input.
78
80 This function is available in glibc since version 2.1.
81
83 POSIX.1-2001.
84
86 iconv_close(3), iconv_open(3)
87
89 This page is part of release 3.25 of the Linux man-pages project. A
90 description of the project, and information about reporting bugs, can
91 be found at http://www.kernel.org/doc/man-pages/.
92
93
94
95GNU 2008-09-08 ICONV(3)