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

NAME

6       iconv - codeset conversion function
7

SYNOPSIS

9       #include <iconv.h>
10
11       size_t iconv(iconv_t cd, char **restrict inbuf,
12              size_t *restrict inbytesleft, char **restrict outbuf,
13              size_t *restrict outbytesleft);
14
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

94       None.
95

APPLICATION USAGE

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

RATIONALE

128       None.
129

FUTURE DIRECTIONS

131       None.
132

SEE ALSO

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