iconv.3c (2010 09)
i
iconv(3C) iconv(3C)
iconv() fails if any of the following conditions are encountered:
[EILSEQ] Input conversion stopped due to an input character that does not belong to the input
codeset, or if the conversion table does not contain an entry corresponding to this
input character and a galley character was not defined for that particular table.
[E2BIG] Input conversion stopped due to lack of space in the output buffer.
[EINVAL] Input conversion stopped due to an incomplete character or shift sequence at the
end of the input buffer.
[EBADF] The cd argument is not a valid open conversion descriptor.
iconv_close()
fails if any of the following conditions are encountered:
[EBADF] The conversion descriptor is invalid.
EXAMPLES
The following example shows how the
iconv() interfaces maybe used for conversions.
#include <iconv.h>
#include <errno.h>
main()
{
...
convert("roman8", "iso88591", fd);
...
}
int
convert(tocode, fromcode, Input)
char *tocode; /* tocode name */
char *fromcode /* fromcode name */
int Input; /* input file descriptor */
{
extern void error(); /* local error message */
iconv_t cd; /* conversion descriptor */
unsigned char *table; /* ptr to translation table */
int bytesread; /* num bytes read into input buffer */
unsigned char inbuf[BUFSIZ]; /* input buffer */
unsigned char *inchar; /* ptr to input character */
size_t inbytesleft; /* num bytes left in input buffer */
unsigned char outbuf[BUFSIZ]; /* output buffer */
unsigned char *outchar; /* ptr to output character */
size_t outbytesleft; /* num bytes left in output buffer */
size_t ret_val; /* number of conversions */
/* Initiate conversion -- get conversion descriptor */
if ((cd = iconv_open(tocode, fromcode)) == (iconv_t)-1) {
error(FATAL, BAD_OPEN);
}
inbytesleft = 0; /* no. of bytes converted */
/* translate the characters */
for ( ;; ) {
/*
* if any bytes are leftover, they will be in the
* beginning of the buffer on the next read().
*/
inchar = inbuf; /* points to input buffer */
outchar = outbuf; /* points to output buffer */
outbytesleft = BUFSIZ; /* no of bytes to be converted */
if ((bytesread = read(Input, inbuf+inbytesleft,
HP-UX 11i Version 3: September 2010 − 3 − Hewlett-Packard Company 3