1ICONV(3)                   Linux Programmer's Manual                  ICONV(3)
2
3
4

NAME

6       iconv - perform character set conversion
7

SYNOPSIS

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

DESCRIPTION

16       The argument cd must be a conversion descriptor created using the func‐
17       tion iconv_open().
18
19       The main case is when inbuf is not NULL and *inbuf  is  not  NULL.   In
20       this  case, the iconv() function converts the multibyte sequence start‐
21       ing at *inbuf to a multibyte sequence starting  at  *outbuf.   At  most
22       *inbytesleft  bytes,  starting  at *inbuf, will be read.  At most *out‐
23       bytesleft bytes, starting at *outbuf, will be written.
24
25       The iconv() function converts one multibyte character at  a  time,  and
26       for  each  character  conversion  it  increments  *inbuf and decrements
27       *inbytesleft by the number of  converted  input  bytes,  it  increments
28       *outbuf  and decrements *outbytesleft by the number of converted output
29       bytes, and it updates the conversion state contained in cd.   The  con‐
30       version can stop for four reasons:
31
32       1.  An  invalid multibyte sequence is encountered in the input. In this
33       case it sets errno to EILSEQ and returns (size_t)(-1). *inbuf  is  left
34       pointing to the beginning of the invalid multibyte sequence.
35
36       2.   The   input  byte  sequence  has  been  entirely  converted,  i.e.
37       *inbytesleft has gone down to 0. In this case iconv() returns the  num‐
38       ber of non-reversible conversions performed during this call.
39
40       3.  An  incomplete  multibyte sequence is encountered in the input, and
41       the input byte sequence terminates after it. In this case it sets errno
42       to  EINVAL  and  returns  (size_t)(-1).  *inbuf is left pointing to the
43       beginning of the incomplete multibyte sequence.
44
45       4. The output buffer has no more room for the next converted character.
46       In this case it sets errno to E2BIG and returns (size_t)(-1).
47
48       A different case is when inbuf is NULL or *inbuf is NULL, but outbuf is
49       not NULL and *outbuf is not NULL. In this case,  the  iconv()  function
50       attempts  to set cd's conversion state to the initial state and store a
51       corresponding shift sequence at *outbuf.  At most *outbytesleft  bytes,
52       starting at *outbuf, will be written.  If the output buffer has no more
53       room for this reset sequence,  it  sets  errno  to  E2BIG  and  returns
54       (size_t)(-1).  Otherwise  it  increments  *outbuf  and decrements *out‐
55       bytesleft by the number of bytes written.
56
57       A third case is when inbuf is NULL or *inbuf is  NULL,  and  outbuf  is
58       NULL  or  *outbuf is NULL. In this case, the iconv() function sets cd's
59       conversion state to the initial state.
60

RETURN VALUE

62       The iconv() function returns the number of characters  converted  in  a
63       non-reversible  way  during  this  call; reversible conversions are not
64       counted.  In case of error, it sets errno and returns (size_t)(-1).
65

ERRORS

67       The following errors can occur, among others:
68
69       E2BIG  There is not sufficient room at *outbuf.
70
71       EILSEQ An invalid multibyte sequence has been encountered in the input.
72
73       EINVAL An incomplete multibyte sequence has  been  encountered  in  the
74              input.
75

CONFORMING TO

77       POSIX.1-2001.
78

SEE ALSO

80       iconv_close(3), iconv_open(3)
81
82
83
84GNU                               2001-11-15                          ICONV(3)
Impressum