]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/iconv.3
fanotify_init.2, fanotify.7: Document FAN_REPORT_TID
[thirdparty/man-pages.git] / man3 / iconv.3
CommitLineData
fea681da
MK
1.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2.\"
89e3ffe9 3.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
fea681da
MK
4.\" This is free documentation; you can redistribute it and/or
5.\" modify it under the terms of the GNU General Public License as
6.\" published by the Free Software Foundation; either version 2 of
7.\" the License, or (at your option) any later version.
fe382ebf 8.\" %%%LICENSE_END
fea681da
MK
9.\"
10.\" References consulted:
11.\" GNU glibc-2 source code and manual
008f1ecc 12.\" OpenGroup's Single UNIX specification
3876c0e5 13.\" http://www.UNIX-systems.org/online.html
fea681da
MK
14.\"
15.\" 2000-06-30 correction by Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
16.\" 2000-11-15 aeb, fixed prototype
17.\"
4b8c67d9 18.TH ICONV 3 2017-09-15 "GNU" "Linux Programmer's Manual"
fea681da
MK
19.SH NAME
20iconv \- perform character set conversion
21.SH SYNOPSIS
22.nf
23.B #include <iconv.h>
68e4db0a 24.PP
fea681da 25.BI "size_t iconv(iconv_t " cd ,
b9f02710
MK
26.BI " char **" inbuf ", size_t *" inbytesleft ,
27.BI " char **" outbuf ", size_t *" outbytesleft );
fea681da
MK
28.fi
29.SH DESCRIPTION
f9b75bd4
MK
30The
31.BR iconv ()
32function converts a sequence of characters in one character encoding
33to a sequence of characters in another character encoding.
34The
35.I cd
36argument is a conversion descriptor,
37previously created by a call to
38.BR iconv_open (3);
39the conversion descriptor defines the character encodings that
40.BR iconv ()
41uses for the conversion.
42The
43.I inbuf
44argument is the address of a variable that points to
45the first character of the input sequence;
46.I inbytesleft
47indicates the number of bytes in that buffer.
48The
49.I outbuf
50argument is the address of a variable that points to
51the first byte available in the output buffer;
52.I outbytesleft
53indicates the number of bytes available in the output buffer.
fea681da
MK
54.PP
55The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL.
60a90ecd
MK
56In this case, the
57.BR iconv ()
58function converts the multibyte sequence
fea681da
MK
59starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP.
60At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read.
61At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
62.PP
60a90ecd
MK
63The
64.BR iconv ()
65function converts one multibyte character at a time, and for
fea681da
MK
66each character conversion it increments \fI*inbuf\fP and decrements
67\fI*inbytesleft\fP by the number of converted input bytes, it increments
68\fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted
69output bytes, and it updates the conversion state contained in \fIcd\fP.
037273a6
MK
70If the character encoding of the input is stateful, the
71.BR iconv ()
72function can also convert a sequence of input bytes
73to an update to the conversion state without producing any output bytes;
74such input is called a \fIshift sequence\fP.
fea681da 75The conversion can stop for four reasons:
f9b75bd4
MK
76.IP 1. 3
77An invalid multibyte sequence is encountered in the input.
cfa65d73 78In this case,
7d2cb9d5 79it sets \fIerrno\fP to \fBEILSEQ\fP and returns
009df872 80.IR (size_t)\ \-1 .
7d2cb9d5 81\fI*inbuf\fP
fea681da 82is left pointing to the beginning of the invalid multibyte sequence.
f9b75bd4
MK
83.IP 2.
84The input byte sequence has been entirely converted,
75b94dc3 85that is, \fI*inbytesleft\fP has gone down to 0.
cfa65d73 86In this case,
60a90ecd
MK
87.BR iconv ()
88returns the number of
24b74457 89nonreversible conversions performed during this call.
f9b75bd4
MK
90.IP 3.
91An incomplete multibyte sequence is encountered in the input, and the
c13182ef 92input byte sequence terminates after it.
fa51e6a4 93In this case, it sets \fIerrno\fP to
7d2cb9d5 94\fBEINVAL\fP and returns
009df872 95.IR (size_t)\ \-1 .
7d2cb9d5 96\fI*inbuf\fP is left pointing to the
fea681da 97beginning of the incomplete multibyte sequence.
f9b75bd4
MK
98.IP 4.
99The output buffer has no more room for the next converted character.
fa51e6a4 100In this case, it sets \fIerrno\fP to \fBE2BIG\fP and returns
009df872 101.IR (size_t)\ \-1 .
fea681da
MK
102.PP
103A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but
c13182ef
MK
104\fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL.
105In this case, the
60a90ecd
MK
106.BR iconv ()
107function attempts to set \fIcd\fP's conversion state to the
fea681da
MK
108initial state and store a corresponding shift sequence at \fI*outbuf\fP.
109At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
110If the output buffer has no more room for this reset sequence, it sets
7d2cb9d5 111\fIerrno\fP to \fBE2BIG\fP and returns
009df872 112.IR (size_t)\ \-1 .
2b9b829d 113Otherwise, it increments
fea681da
MK
114\fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes
115written.
116.PP
117A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and
c13182ef 118\fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL.
60a90ecd
MK
119In this case, the
120.BR iconv ()
fea681da 121function sets \fIcd\fP's conversion state to the initial state.
47297adb 122.SH RETURN VALUE
60a90ecd
MK
123The
124.BR iconv ()
125function returns the number of characters converted in a
24b74457 126nonreversible way during this call; reversible conversions are not counted.
7d2cb9d5 127In case of error, it sets \fIerrno\fP and returns
009df872 128.IR (size_t)\ \-1 .
fea681da
MK
129.SH ERRORS
130The following errors can occur, among others:
131.TP
132.B E2BIG
133There is not sufficient room at \fI*outbuf\fP.
134.TP
135.B EILSEQ
136An invalid multibyte sequence has been encountered in the input.
137.TP
138.B EINVAL
139An incomplete multibyte sequence has been encountered in the input.
3fd4929b
MK
140.SH VERSIONS
141This function is available in glibc since version 2.1.
e5ea2ae7 142.SH ATTRIBUTES
fe3ac773
MK
143For an explanation of the terms used in this section, see
144.BR attributes (7).
145.TS
146allbox;
147lb lb lb
148l l l.
149Interface Attribute Value
150T{
e5ea2ae7 151.BR iconv ()
a353619d 152T} Thread safety MT-Safe race:cd
fe3ac773 153.TE
a353619d
PH
154.PP
155The
156.BR iconv ()
157function is MT-Safe, as long as callers arrange for
158mutual exclusion on the
159.I cd
160argument.
47297adb 161.SH CONFORMING TO
21151fe5 162POSIX.1-2001, POSIX.1-2008.
2d17a61d 163.SH NOTES
c89ca436
AB
164In each series of calls to
165.BR iconv (),
166the last should be one with \fIinbuf\fP or \fI*inbuf\fP equal to NULL,
167in order to flush out any partially converted input.
847e0d88 168.PP
2d17a61d
MK
169Although
170.I inbuf
171and
172.I outbuf
173are typed as
174.IR "char\ **" ,
175this does not mean that the objects they point can be interpreted
176as C strings or as arrays of characters:
177the interpretation of character byte sequences is
178handled internally by the conversion functions.
179In some encodings, a zero byte may be a valid part of a multibyte character.
847e0d88 180.PP
2d17a61d
MK
181The caller of
182.BR iconv ()
183must ensure that the pointers passed to the function are suitable
184for accessing characters in the appropriate character set.
185This includes ensuring correct alignment on platforms that have
186tight restrictions on alignment.
47297adb 187.SH SEE ALSO
fea681da 188.BR iconv_close (3),
054f9fb2
MK
189.BR iconv_open (3),
190.BR iconvconfig (8)