2 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
4 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\" References consulted:
7 .\" GNU glibc-2 source code and manual
8 .\" OpenGroup's Single UNIX specification
9 .\" http://www.UNIX-systems.org/online.html
11 .\" 2000-06-30 correction by Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
12 .\" 2000-11-15 aeb, fixed prototype
14 .TH iconv 3 (date) "Linux man-pages (unreleased)"
16 iconv \- perform character set conversion
19 .RI ( libc ", " \-lc )
24 .BI "size_t iconv(iconv_t " cd ,
25 .BI " char **restrict " inbuf ", size_t *restrict " inbytesleft ,
26 .BI " char **restrict " outbuf ", size_t *restrict " outbytesleft );
31 function converts a sequence of characters in one character encoding
32 to a sequence of characters in another character encoding.
35 argument is a conversion descriptor,
36 previously created by a call to
38 the conversion descriptor defines the character encodings that
40 uses for the conversion.
43 argument is the address of a variable that points to
44 the first character of the input sequence;
46 indicates the number of bytes in that buffer.
49 argument is the address of a variable that points to
50 the first byte available in the output buffer;
52 indicates the number of bytes available in the output buffer.
54 The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL.
57 function converts the multibyte sequence
58 starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP.
59 At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read.
60 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
64 function converts one multibyte character at a time, and for
65 each character conversion it increments \fI*inbuf\fP and decrements
66 \fI*inbytesleft\fP by the number of converted input bytes, it increments
67 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted
68 output bytes, and it updates the conversion state contained in \fIcd\fP.
69 If the character encoding of the input is stateful, the
71 function can also convert a sequence of input bytes
72 to an update to the conversion state without producing any output bytes;
73 such input is called a \fIshift sequence\fP.
74 The conversion can stop for four reasons:
76 An invalid multibyte sequence is encountered in the input.
78 it sets \fIerrno\fP to \fBEILSEQ\fP and returns
81 is left pointing to the beginning of the invalid multibyte sequence.
83 The input byte sequence has been entirely converted,
84 that is, \fI*inbytesleft\fP has gone down to 0.
88 nonreversible conversions performed during this call.
90 An incomplete multibyte sequence is encountered in the input, and the
91 input byte sequence terminates after it.
92 In this case, it sets \fIerrno\fP to
93 \fBEINVAL\fP and returns
95 \fI*inbuf\fP is left pointing to the
96 beginning of the incomplete multibyte sequence.
98 The output buffer has no more room for the next converted character.
99 In this case, it sets \fIerrno\fP to \fBE2BIG\fP and returns
102 A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but
103 \fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL.
106 function attempts to set \fIcd\fP's conversion state to the
107 initial state and store a corresponding shift sequence at \fI*outbuf\fP.
108 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
109 If the output buffer has no more room for this reset sequence, it sets
110 \fIerrno\fP to \fBE2BIG\fP and returns
112 Otherwise, it increments
113 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes
116 A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and
117 \fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL.
120 function sets \fIcd\fP's conversion state to the initial state.
124 function returns the number of characters converted in a
125 nonreversible way during this call; reversible conversions are not counted.
132 to indicate the error.
134 The following errors can occur, among others:
137 There is not sufficient room at \fI*outbuf\fP.
140 An invalid multibyte sequence has been encountered in the input.
143 An incomplete multibyte sequence has been encountered in the input.
145 This function is available since glibc 2.1.
147 For an explanation of the terms used in this section, see
155 Interface Attribute Value
158 T} Thread safety MT-Safe race:cd
166 function is MT-Safe, as long as callers arrange for
167 mutual exclusion on the
171 POSIX.1-2001, POSIX.1-2008.
173 In each series of calls to
175 the last should be one with \fIinbuf\fP or \fI*inbuf\fP equal to NULL,
176 in order to flush out any partially converted input.
184 this does not mean that the objects they point can be interpreted
185 as C strings or as arrays of characters:
186 the interpretation of character byte sequences is
187 handled internally by the conversion functions.
188 In some encodings, a zero byte may be a valid part of a multibyte character.
192 must ensure that the pointers passed to the function are suitable
193 for accessing characters in the appropriate character set.
194 This includes ensuring correct alignment on platforms that have
195 tight restrictions on alignment.