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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

97       None.
98

APPLICATION USAGE

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

RATIONALE

131       None.
132

FUTURE DIRECTIONS

134       None.
135

SEE ALSO

137       iconv_open(), iconv_close(), mbsrtowcs()
138
139       The Base Definitions volume of POSIX.1‐2017, <iconv.h>
140
142       Portions of this text are reprinted and reproduced in  electronic  form
143       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
144       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
145       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
146       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
147       event of any discrepancy between this version and the original IEEE and
148       The Open Group Standard, the original IEEE and The Open Group  Standard
149       is  the  referee document. The original Standard can be obtained online
150       at http://www.opengroup.org/unix/online.html .
151
152       Any typographical or formatting errors that appear  in  this  page  are
153       most likely to have been introduced during the conversion of the source
154       files to man page format. To report such errors,  see  https://www.ker
155       nel.org/doc/man-pages/reporting_bugs.html .
156
157
158
159IEEE/The Open Group                  2017                            ICONV(3P)
Impressum