1 | .\" Copyright (c) Bruno Haible <bruno@clisp.org> |
---|
2 | .\" |
---|
3 | .\" This is free documentation; you can redistribute it and/or |
---|
4 | .\" modify it under the terms of the GNU General Public License as |
---|
5 | .\" published by the Free Software Foundation; either version 2 of |
---|
6 | .\" the License, or (at your option) any later version. |
---|
7 | .\" |
---|
8 | .\" References consulted: |
---|
9 | .\" GNU glibc-2 source code and manual |
---|
10 | .\" OpenGroup's Single Unix specification http://www.UNIX-systems.org/online.html |
---|
11 | .\" |
---|
12 | .TH ICONV 3 "January 21, 2004" "GNU" "Linux Programmer's Manual" |
---|
13 | .SH NAME |
---|
14 | iconv \- perform character set conversion |
---|
15 | .SH SYNOPSIS |
---|
16 | .nf |
---|
17 | .B #include <iconv.h> |
---|
18 | .sp |
---|
19 | .BI "size_t iconv (iconv_t " cd , |
---|
20 | .BI " const char* * " inbuf ", size_t * "inbytesleft , |
---|
21 | .BI " char* * " outbuf ", size_t * "outbytesleft ); |
---|
22 | .fi |
---|
23 | .SH DESCRIPTION |
---|
24 | The argument \fIcd\fP must be a conversion descriptor created using the |
---|
25 | function \fBiconv_open\fP. |
---|
26 | .PP |
---|
27 | The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL. |
---|
28 | In this case, the \fBiconv\fP function converts the multibyte sequence |
---|
29 | starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP. |
---|
30 | At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read. |
---|
31 | At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written. |
---|
32 | .PP |
---|
33 | The \fBiconv\fP function converts one multibyte character at a time, and for |
---|
34 | each character conversion it increments \fI*inbuf\fP and decrements |
---|
35 | \fI*inbytesleft\fP by the number of converted input bytes, it increments |
---|
36 | \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted |
---|
37 | output bytes, and it updates the conversion state contained in \fIcd\fP. |
---|
38 | The conversion can stop for four reasons: |
---|
39 | .PP |
---|
40 | 1. An invalid multibyte sequence is encountered in the input. In this case |
---|
41 | it sets \fBerrno\fP to \fBEILSEQ\fP and returns (size_t)(-1). \fI*inbuf\fP |
---|
42 | is left pointing to the beginning of the invalid multibyte sequence. |
---|
43 | .PP |
---|
44 | 2. The input byte sequence has been entirely converted, i.e. \fI*inbytesleft\fP |
---|
45 | has gone down to 0. In this case \fBiconv\fP returns the number of |
---|
46 | non-reversible conversions performed during this call. |
---|
47 | .PP |
---|
48 | 3. An incomplete multibyte sequence is encountered in the input, and the |
---|
49 | input byte sequence terminates after it. In this case it sets \fBerrno\fP to |
---|
50 | \fBEINVAL\fP and returns (size_t)(-1). \fI*inbuf\fP is left pointing to the |
---|
51 | beginning of the incomplete multibyte sequence. |
---|
52 | .PP |
---|
53 | 4. The output buffer has no more room for the next converted character. In |
---|
54 | this case it sets \fBerrno\fP to \fBE2BIG\fP and returns (size_t)(-1). |
---|
55 | .PP |
---|
56 | A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but |
---|
57 | \fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL. In this case, the |
---|
58 | \fBiconv\fP function attempts to set \fIcd\fP's conversion state to the |
---|
59 | initial state and store a corresponding shift sequence at \fI*outbuf\fP. |
---|
60 | At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written. |
---|
61 | If the output buffer has no more room for this reset sequence, it sets |
---|
62 | \fBerrno\fP to \fBE2BIG\fP and returns (size_t)(-1). Otherwise it increments |
---|
63 | \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes |
---|
64 | written. |
---|
65 | .PP |
---|
66 | A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and |
---|
67 | \fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL. In this case, the \fBiconv\fP |
---|
68 | function sets \fIcd\fP's conversion state to the initial state. |
---|
69 | .SH "RETURN VALUE" |
---|
70 | The \fBiconv\fP function returns the number of characters converted in a |
---|
71 | non-reversible way during this call; reversible conversions are not counted. |
---|
72 | In case of error, it sets \fBerrno\fP and returns (size_t)(-1). |
---|
73 | .SH ERRORS |
---|
74 | The following errors can occur, among others: |
---|
75 | .TP |
---|
76 | .B E2BIG |
---|
77 | There is not sufficient room at \fI*outbuf\fP. |
---|
78 | .TP |
---|
79 | .B EILSEQ |
---|
80 | An invalid multibyte sequence has been encountered in the input. |
---|
81 | .TP |
---|
82 | .B EINVAL |
---|
83 | An incomplete multibyte sequence has been encountered in the input. |
---|
84 | .SH "CONFORMING TO" |
---|
85 | UNIX98 |
---|
86 | .SH "SEE ALSO" |
---|
87 | .BR iconv_open "(3), " iconv_close (3) |
---|