man-pages/man3/iconv.3

93 lines
4.0 KiB
Groff
Raw Normal View History

2004-11-03 13:51:07 +00:00
.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
.\"
.\" This is free documentation; you can redistribute it and/or
.\" modify it under the terms of the GNU General Public License as
.\" published by the Free Software Foundation; either version 2 of
.\" the License, or (at your option) any later version.
.\"
.\" References consulted:
.\" GNU glibc-2 source code and manual
.\" OpenGroup's Single Unix specification
.\" http://www.UNIX-systems.org/online.html
2004-11-03 13:51:07 +00:00
.\"
.\" 2000-06-30 correction by Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
.\" 2000-11-15 aeb, fixed prototype
.\"
.TH ICONV 3 2001-11-15 "GNU" "Linux Programmer's Manual"
.SH NAME
iconv \- perform character set conversion
.SH SYNOPSIS
.nf
.B #include <iconv.h>
.sp
.BI "size_t iconv(iconv_t " cd ,
2007-04-03 15:32:52 +00:00
.BI " char **" inbuf ", size_t *" inbytesleft ,
.BI " char **" outbuf ", size_t *" outbytesleft );
2004-11-03 13:51:07 +00:00
.fi
.SH DESCRIPTION
The argument \fIcd\fP must be a conversion descriptor created using the
2005-10-19 08:35:30 +00:00
function \fBiconv_open\fP().
2004-11-03 13:51:07 +00:00
.PP
The main case is when \fIinbuf\fP is not NULL and \fI*inbuf\fP is not NULL.
In this case, the \fBiconv\fP() function converts the multibyte sequence
2004-11-03 13:51:07 +00:00
starting at \fI*inbuf\fP to a multibyte sequence starting at \fI*outbuf\fP.
At most \fI*inbytesleft\fP bytes, starting at \fI*inbuf\fP, will be read.
At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
.PP
The \fBiconv\fP() function converts one multibyte character at a time, and for
2004-11-03 13:51:07 +00:00
each character conversion it increments \fI*inbuf\fP and decrements
\fI*inbytesleft\fP by the number of converted input bytes, it increments
\fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of converted
output bytes, and it updates the conversion state contained in \fIcd\fP.
The conversion can stop for four reasons:
.PP
1. An invalid multibyte sequence is encountered in the input. In this case
2006-02-09 20:29:51 +00:00
it sets \fIerrno\fP to \fBEILSEQ\fP and returns (size_t)(\-1). \fI*inbuf\fP
2004-11-03 13:51:07 +00:00
is left pointing to the beginning of the invalid multibyte sequence.
.PP
2. The input byte sequence has been entirely converted, i.e. \fI*inbytesleft\fP
has gone down to 0. In this case \fBiconv\fP() returns the number of
2004-11-03 13:51:07 +00:00
non-reversible conversions performed during this call.
.PP
3. An incomplete multibyte sequence is encountered in the input, and the
2006-02-09 20:29:51 +00:00
input byte sequence terminates after it. In this case it sets \fIerrno\fP to
2005-07-06 12:57:38 +00:00
\fBEINVAL\fP and returns (size_t)(\-1). \fI*inbuf\fP is left pointing to the
2004-11-03 13:51:07 +00:00
beginning of the incomplete multibyte sequence.
.PP
4. The output buffer has no more room for the next converted character. In
2006-02-09 20:29:51 +00:00
this case it sets \fIerrno\fP to \fBE2BIG\fP and returns (size_t)(\-1).
2004-11-03 13:51:07 +00:00
.PP
A different case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, but
\fIoutbuf\fP is not NULL and \fI*outbuf\fP is not NULL. In this case, the
\fBiconv\fP() function attempts to set \fIcd\fP's conversion state to the
2004-11-03 13:51:07 +00:00
initial state and store a corresponding shift sequence at \fI*outbuf\fP.
At most \fI*outbytesleft\fP bytes, starting at \fI*outbuf\fP, will be written.
If the output buffer has no more room for this reset sequence, it sets
2006-02-09 20:29:51 +00:00
\fIerrno\fP to \fBE2BIG\fP and returns (size_t)(\-1). Otherwise it increments
2004-11-03 13:51:07 +00:00
\fI*outbuf\fP and decrements \fI*outbytesleft\fP by the number of bytes
written.
.PP
A third case is when \fIinbuf\fP is NULL or \fI*inbuf\fP is NULL, and
\fIoutbuf\fP is NULL or \fI*outbuf\fP is NULL. In this case, the \fBiconv\fP()
2004-11-03 13:51:07 +00:00
function sets \fIcd\fP's conversion state to the initial state.
.SH "RETURN VALUE"
The \fBiconv\fP() function returns the number of characters converted in a
2004-11-03 13:51:07 +00:00
non-reversible way during this call; reversible conversions are not counted.
2006-02-09 20:29:51 +00:00
In case of error, it sets \fIerrno\fP and returns (size_t)(\-1).
2004-11-03 13:51:07 +00:00
.SH ERRORS
The following errors can occur, among others:
.TP
.B E2BIG
There is not sufficient room at \fI*outbuf\fP.
.TP
.B EILSEQ
An invalid multibyte sequence has been encountered in the input.
.TP
.B EINVAL
An incomplete multibyte sequence has been encountered in the input.
.SH "CONFORMING TO"
POSIX.1-2001.
2004-11-03 13:51:07 +00:00
.SH "SEE ALSO"
.BR iconv_close (3),
.BR iconv_open (3)