HP-UX Reference (11i v1 05/09) - 3 Library Functions A-M (vol 6)

i
iconv(3C) iconv(3C)
return BAD;
}
/* iconv() returns the number of non-identical conversions
* performed. If the entire string in the input buffer is
* converted, the value pointed to by inbytesleft will be
* zero. If the conversion stopped due to any reason, the
* value pointed to by inbytesleft will be non-zero and
* errno is set to indicate the condition.
*/
if ((ret_val == -1) && (errno == EINVAL)) {
/* Input conversion stopped due to an incomplete
* character or shift sequence at the end of the
* input buffer.
*/
/* Copy data left, to the start of buffer */
memcpy((char *)inbuf, (char *)inchar,
(size_t)inbytesleft);
} else if ((ret_val == -1) && (errno == EILSEQ)) {
/* Input conversion stopped due to an input byte
* that does not belong to the input codeset.
*/
error(FATAL, BAD_CONVERSION);
} else if ((ret_val == -1) && (errno == E2BIG)) {
/* Input conversion stopped due to lack of space
* in the output buffer. inbytesleft has the
* number of bytes to be converted.
*/
memcpy((char *)inbuf, (char *)inchar,
(size_t)inbytesleft);
}
/* Go back and read from the input file. */
}
/* end conversion & get rid of the conversion table */
if (iconv_close(cd) == BAD) {
error(FATAL, BAD_CLOSE);
}
return GOOD;
}
WARNINGS
If you use iconv() and compile/link your application archive, note that iconv() has a dependency on
libdld.sl that will require a change to the compile/link command:
Compile :
cc -Wl,-a,archive -Wl,-E -Wl,+n -l:libdld.sl -o outfile source
Or compile with CCOPTS and LDOPTS:
export CCOPTS="-Wl,-a,archive options -Wl,-E -l:libdld.sl"
export LDOPTS="
options -E +n -l:libdld.sl"
cc -o
outfile source
The option -Wl,-a,archive is positionally dependent and should occur at the beginning of the compile
line. For optimum compatibility in future releases, you should avoid using archive libc with other shared
libraries except for libdld.sl as needed above.
There is a corner-case situation for multi-byte characters that is not correctly handled by iconv(). If the
last character in the file being converted is an invalid multi-byte character, iconv() returns [EINVAL]
instead of [EILSEQ]. The application can get around this by checking whether EOF is reached or if this is
the last buffer being converted. In this case, [EINVAL] should be treated as [EILSEQ].
Section 3466 Hewlett-Packard Company 4 HP-UX 11i Version 1: September 2005