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

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
i
iconv(3C) iconv(3C)
if (write(1, outbuf, (size_t)BUFSIZ-outbytesleft) < 0) {
perror("prog");
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(3C) and compile/link your application archive, please note that iconv(3C) 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(3C). If the
last character in the file being converted is an invalid multi-byte character, iconv(3C) returns EINVAL
instead of EILSEQ. The application can get around this by checking whether EOF is reached or if this is
Section 3438 4 HP-UX Release 11i: December 2000
___
___