1ICONV(3P)                  POSIX Programmer's Manual                 ICONV(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       iconv - codeset conversion function
13

SYNOPSIS

15       #include <iconv.h>
16
17       size_t iconv(iconv_t cd, char **restrict inbuf,
18              size_t *restrict inbytesleft, char **restrict outbuf,
19              size_t *restrict outbytesleft);
20
21

DESCRIPTION

23       The iconv() function shall convert the sequence of characters from  one
24       codeset,  in  the  array  specified by inbuf, into a sequence of corre‐
25       sponding characters in another codeset, in the array specified by  out‐
26       buf.  The  codesets  are  those specified in the iconv_open() call that
27       returned the conversion descriptor, cd. The inbuf argument points to  a
28       variable  that  points  to  the first character in the input buffer and
29       inbytesleft indicates the number of bytes to the end of the  buffer  to
30       be  converted.  The outbuf argument points to a variable that points to
31       the first available byte in the output buffer  and  outbytesleft  indi‐
32       cates the number of the available bytes to the end of the buffer.
33
34       For  state-dependent  encodings, the conversion descriptor cd is placed
35       into its initial shift state by a  call  for  which  inbuf  is  a  null
36       pointer,  or  for which inbuf points to a null pointer. When iconv() is
37       called in this way, and if outbuf is not a null pointer or a pointer to
38       a  null  pointer,  and outbytesleft points to a positive value, iconv()
39       shall place, into the output buffer, the byte sequence  to  change  the
40       output  buffer  to its initial shift state. If the output buffer is not
41       large enough to hold the entire reset sequence, iconv() shall fail  and
42       set errno to [E2BIG].  Subsequent calls with inbuf as other than a null
43       pointer or a pointer to a null pointer cause  the  conversion  to  take
44       place from the current state of the conversion descriptor.
45
46       If  a  sequence  of  input bytes does not form a valid character in the
47       specified codeset, conversion shall stop after  the  previous  success‐
48       fully  converted character. If the input buffer ends with an incomplete
49       character or shift sequence, conversion shall stop after  the  previous
50       successfully  converted bytes. If the output buffer is not large enough
51       to hold the entire converted input, conversion shall stop just prior to
52       the  input  bytes  that  would cause the output buffer to overflow. The
53       variable pointed to by inbuf shall be updated to point to the byte fol‐
54       lowing  the  last  byte  successfully used in the conversion. The value
55       pointed to by inbytesleft shall be decremented to reflect the number of
56       bytes  still not converted in the input buffer. The variable pointed to
57       by outbuf shall be updated to point to the byte following the last byte
58       of converted output data. The value pointed to by outbytesleft shall be
59       decremented to reflect the number of bytes still available in the  out‐
60       put  buffer.  For  state-dependent encodings, the conversion descriptor
61       shall be updated to reflect the shift state in effect at the end of the
62       last successfully converted byte sequence.
63
64       If  iconv()  encounters  a character in the input buffer that is valid,
65       but for which an identical character does not exist in the target code‐
66       set, iconv() shall perform an implementation-defined conversion on this
67       character.
68

RETURN VALUE

70       The iconv() function shall update the variables pointed to by the argu‐
71       ments  to reflect the extent of the conversion and return the number of
72       non-identical conversions performed. If the entire string in the  input
73       buffer is converted, the value pointed to by inbytesleft shall be 0. If
74       the input conversion is stopped due to any conditions mentioned  above,
75       the  value  pointed to by inbytesleft shall be non-zero and errno shall
76       be set to indicate the condition. If an  error  occurs,  iconv()  shall
77       return (size_t)-1 and set errno to indicate the error.
78

ERRORS

80       The iconv() function shall fail if:
81
82       EILSEQ Input  conversion  stopped  due  to  an input byte that does not
83              belong to the input codeset.
84
85       E2BIG  Input conversion stopped due to lack of space in the output buf‐
86              fer.
87
88       EINVAL Input conversion stopped due to an incomplete character or shift
89              sequence at the end of the input buffer.
90
91
92       The iconv() function may fail if:
93
94       EBADF  The cd argument is not a valid open conversion descriptor.
95
96
97       The following sections are informative.
98

EXAMPLES

100       None.
101

APPLICATION USAGE

103       The inbuf argument indirectly points to the memory area which  contains
104       the conversion input data. The outbuf argument indirectly points to the
105       memory area which is to contain  the  result  of  the  conversion.  The
106       objects indirectly pointed to by inbuf and outbuf are not restricted to
107       containing data that is directly representable in  the  ISO C  standard
108       language  char  data  type. The type of inbuf and outbuf, char **, does
109       not imply that the objects pointed to are  interpreted  as  null-termi‐
110       nated  C strings or arrays of characters.  Any interpretation of a byte
111       sequence that represents a character in a given character set  encoding
112       scheme  is  done internally within the codeset converters. For example,
113       the area pointed to indirectly by inbuf and/or outbuf can  contain  all
114       zero octets that are not interpreted as string terminators but as coded
115       character data according to the respective codeset encoding scheme. The
116       type  of the data ( char, short, long, and so on) read or stored in the
117       objects is not specified, but may be inferred for both  the  input  and
118       output  data  by  the  converters determined by the fromcode and tocode
119       arguments of iconv_open().
120
121       Regardless of the data type inferred by the converter, the size of  the
122       remaining  space in both input and output objects (the intbytesleft and
123       outbytesleft arguments) is always measured in bytes.
124
125       For implementations that  support  the  conversion  of  state-dependent
126       encodings, the conversion descriptor must be able to accurately reflect
127       the shift-state in effect at the end of the last successful conversion.
128       It  is  not  required that the conversion descriptor itself be updated,
129       which would require it to be a pointer type. Thus, implementations  are
130       free  to  implement  the  descriptor  as a handle (other than a pointer
131       type) by which the conversion information can be accessed and updated.
132

RATIONALE

134       None.
135

FUTURE DIRECTIONS

137       None.
138

SEE ALSO

140       iconv_open(),   iconv_close(),   the   Base   Definitions   volume   of
141       IEEE Std 1003.1-2001, <iconv.h>
142
144       Portions  of  this text are reprinted and reproduced in electronic form
145       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
146       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
147       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
148       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
149       event of any discrepancy between this version and the original IEEE and
150       The  Open Group Standard, the original IEEE and The Open Group Standard
151       is the referee document. The original Standard can be  obtained  online
152       at http://www.opengroup.org/unix/online.html .
153
154
155
156IEEE/The Open Group                  2003                            ICONV(3P)
Impressum