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
11

NAME

13       iconv — codeset conversion function
14

SYNOPSIS

16       #include <iconv.h>
17
18       size_t iconv(iconv_t cd, char **restrict inbuf,
19           size_t *restrict inbytesleft, char **restrict outbuf,
20           size_t *restrict outbytesleft);
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       The iconv() function may fail if:
92
93       EBADF  The cd argument is not a valid open conversion descriptor.
94
95       The following sections are informative.
96

EXAMPLES

98       None.
99

APPLICATION USAGE

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

RATIONALE

132       None.
133

FUTURE DIRECTIONS

135       None.
136

SEE ALSO

138       iconv_open(), iconv_close(), mbsrtowcs()
139
140       The Base Definitions volume of POSIX.1‐2008, <iconv.h>
141
143       Portions of this text are reprinted and reproduced in  electronic  form
144       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
145       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
146       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
147       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
148       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) 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.unix.org/online.html .
153
154       Any  typographical  or  formatting  errors that appear in this page are
155       most likely to have been introduced during the conversion of the source
156       files  to  man page format. To report such errors, see https://www.ker
157       nel.org/doc/man-pages/reporting_bugs.html .
158
159
160
161IEEE/The Open Group                  2013                            ICONV(3P)
Impressum