OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / original / man3 / iconv.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.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
11 .\"     http://www.UNIX-systems.org/online.html
12 .\"
13 .\" 2000-06-30 correction by Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
14 .\" 2000-11-15 aeb, fixed prototype
15 .\"
16 .TH ICONV 3 2008-09-08 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 iconv \- perform character set conversion
19 .SH SYNOPSIS
20 .nf
21 .B #include <iconv.h>
22 .sp
23 .BI "size_t iconv(iconv_t " cd ,
24 .BI "             char **" inbuf ", size_t *" inbytesleft ,
25 .BI "             char **" outbuf ", size_t *" outbytesleft );
26 .fi
27 .SH DESCRIPTION
28 The argument \fIcd\fP must be a conversion descriptor created using the
29 function
30 .BR iconv_open (3).
31 .PP
32 The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL.
33 In this case, the
34 .BR iconv ()
35 function converts the multibyte sequence
36 starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP.
37 At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read.
38 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
39 .PP
40 The
41 .BR iconv ()
42 function converts one multibyte character at a time, and for
43 each character conversion it increments \fI*inbuf\fP and decrements
44 \fI*inbytesleft\fP by the number of converted input bytes, it increments
45 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted
46 output bytes, and it updates the conversion state contained in \fIcd\fP.
47 If the character encoding of the input is stateful, the
48 .BR iconv ()
49 function can also convert a sequence of input bytes
50 to an update to the conversion state without producing any output bytes;
51 such input is called a \fIshift sequence\fP.
52 The conversion can stop for four reasons:
53 .PP
54 1. An invalid multibyte sequence is encountered in the input.
55 In this case
56 it sets \fIerrno\fP to \fBEILSEQ\fP and returns
57 .IR (size_t)\ \-1 .
58 \fI*inbuf\fP
59 is left pointing to the beginning of the invalid multibyte sequence.
60 .PP
61 2. The input byte sequence has been entirely converted,
62 that is, \fI*inbytesleft\fP has gone down to 0.
63 In this case
64 .BR iconv ()
65 returns the number of
66 nonreversible conversions performed during this call.
67 .PP
68 3. An incomplete multibyte sequence is encountered in the input, and the
69 input byte sequence terminates after it.
70 In this case it sets \fIerrno\fP to
71 \fBEINVAL\fP and returns
72 .IR (size_t)\ \-1 .
73 \fI*inbuf\fP is left pointing to the
74 beginning of the incomplete multibyte sequence.
75 .PP
76 4. The output buffer has no more room for the next converted character.
77 In this case it sets \fIerrno\fP to \fBE2BIG\fP and returns
78 .IR (size_t)\ \-1 .
79 .PP
80 A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but
81 \fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL.
82 In this case, the
83 .BR iconv ()
84 function attempts to set \fIcd\fP's conversion state to the
85 initial state and store a corresponding shift sequence at \fI*outbuf\fP.
86 At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
87 If the output buffer has no more room for this reset sequence, it sets
88 \fIerrno\fP to \fBE2BIG\fP and returns
89 .IR (size_t)\ \-1 .
90 Otherwise it increments
91 \fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes
92 written.
93 .PP
94 A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and
95 \fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL.
96 In this case, the
97 .BR iconv ()
98 function sets \fIcd\fP's conversion state to the initial state.
99 .SH "RETURN VALUE"
100 The
101 .BR iconv ()
102 function returns the number of characters converted in a
103 nonreversible way during this call; reversible conversions are not counted.
104 In case of error, it sets \fIerrno\fP and returns
105 .IR (size_t)\ \-1 .
106 .SH ERRORS
107 The following errors can occur, among others:
108 .TP
109 .B E2BIG
110 There is not sufficient room at \fI*outbuf\fP.
111 .TP
112 .B EILSEQ
113 An invalid multibyte sequence has been encountered in the input.
114 .TP
115 .B EINVAL
116 An incomplete multibyte sequence has been encountered in the input.
117 .SH VERSIONS
118 This function is available in glibc since version 2.1.
119 .SH "CONFORMING TO"
120 POSIX.1-2001.
121 .SH "SEE ALSO"
122 .BR iconv_close (3),
123 .BR iconv_open (3)