1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
3 .\" SPDX-License-Identifier: GPL-2.0-or-later
5 .\" References consulted:
6 .\" GNU glibc-2 source code and manual
7 .\" OpenGroup's Single UNIX specification
8 .\" http://www.UNIX-systems.org/online.html
10 .\" 2000-06-30 correction by Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
11 .\" 2000-11-15 aeb, fixed prototype
13 .TH iconv 3 (date) "Linux man-pages (unreleased)"
15 iconv \- perform character set conversion
18 .RI ( libc ", " \-lc )
23 .BI "size_t iconv(iconv_t " cd ,
24 .BI " char **restrict " inbuf ", size_t *restrict " inbytesleft ,
25 .BI " char **restrict " outbuf ", size_t *restrict " outbytesleft );
30 function converts a sequence of characters in one character encoding
31 to a sequence of characters in another character encoding.
34 argument is a conversion descriptor,
35 previously created by a call to
37 the conversion descriptor defines the character encodings that
39 uses for the conversion.
42 argument is the address of a variable that points to
43 the first character of the input sequence;
45 indicates the number of bytes in that buffer.
48 argument is the address of a variable that points to
49 the first byte available in the output buffer;
51 indicates the number of bytes available in the output buffer.
53 The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL.
56 function converts the multibyte sequence
57 starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP.
58 At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read.
59 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
63 function converts one multibyte character at a time, and for
64 each character conversion it increments \fI*inbuf\fP and decrements
65 \fI*inbytesleft\fP by the number of converted input bytes, it increments
66 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted
67 output bytes, and it updates the conversion state contained in \fIcd\fP.
68 If the character encoding of the input is stateful, the
70 function can also convert a sequence of input bytes
71 to an update to the conversion state without producing any output bytes;
72 such input is called a \fIshift sequence\fP.
73 The conversion can stop for four reasons:
75 An invalid multibyte sequence is encountered in the input.
77 it sets \fIerrno\fP to \fBEILSEQ\fP and returns
80 is left pointing to the beginning of the invalid multibyte sequence.
82 The input byte sequence has been entirely converted,
83 that is, \fI*inbytesleft\fP has gone down to 0.
87 nonreversible conversions performed during this call.
89 An incomplete multibyte sequence is encountered in the input, and the
90 input byte sequence terminates after it.
91 In this case, it sets \fIerrno\fP to
92 \fBEINVAL\fP and returns
94 \fI*inbuf\fP is left pointing to the
95 beginning of the incomplete multibyte sequence.
97 The output buffer has no more room for the next converted character.
98 In this case, it sets \fIerrno\fP to \fBE2BIG\fP and returns
101 A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but
102 \fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL.
105 function attempts to set \fIcd\fP's conversion state to the
106 initial state and store a corresponding shift sequence at \fI*outbuf\fP.
107 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
108 If the output buffer has no more room for this reset sequence, it sets
109 \fIerrno\fP to \fBE2BIG\fP and returns
111 Otherwise, it increments
112 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes
115 A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and
116 \fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL.
119 function sets \fIcd\fP's conversion state to the initial state.
123 function returns the number of characters converted in a
124 nonreversible way during this call; reversible conversions are not counted.
131 to indicate the error.
133 The following errors can occur, among others:
136 There is not sufficient room at \fI*outbuf\fP.
139 An invalid multibyte sequence has been encountered in the input.
142 An incomplete multibyte sequence has been encountered in the input.
144 This function is available in glibc since version 2.1.
146 For an explanation of the terms used in this section, see
154 Interface Attribute Value
157 T} Thread safety MT-Safe race:cd
165 function is MT-Safe, as long as callers arrange for
166 mutual exclusion on the
170 POSIX.1-2001, POSIX.1-2008.
172 In each series of calls to
174 the last should be one with \fIinbuf\fP or \fI*inbuf\fP equal to NULL,
175 in order to flush out any partially converted input.
183 this does not mean that the objects they point can be interpreted
184 as C strings or as arrays of characters:
185 the interpretation of character byte sequences is
186 handled internally by the conversion functions.
187 In some encodings, a zero byte may be a valid part of a multibyte character.
191 must ensure that the pointers passed to the function are suitable
192 for accessing characters in the appropriate character set.
193 This includes ensuring correct alignment on platforms that have
194 tight restrictions on alignment.