2004-08-01 23:24:47 +04:00
|
|
|
.\" $NetBSD: iconv.3,v 1.11 2004/08/01 19:24:47 wiz Exp $
|
2003-07-04 10:05:28 +04:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c)2003 Citrus Project,
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2004-08-01 23:24:47 +04:00
|
|
|
.Dd August 1, 2004
|
2003-07-04 11:44:19 +04:00
|
|
|
.Dt ICONV 3
|
2003-07-04 10:05:28 +04:00
|
|
|
.Os
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh NAME
|
|
|
|
.Nm iconv_open ,
|
|
|
|
.Nm iconv_close ,
|
|
|
|
.Nm iconv
|
|
|
|
.Nd codeset conversion functions
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In iconv.h
|
|
|
|
.Ft iconv_t
|
2003-07-04 11:44:19 +04:00
|
|
|
.Fn iconv_open "const char *dstname" "const char *srcname"
|
2003-07-04 10:05:28 +04:00
|
|
|
.Ft int
|
|
|
|
.Fn iconv_close "iconv_t cd"
|
|
|
|
.Ft size_t
|
2004-08-01 21:07:15 +04:00
|
|
|
.Fn iconv "iconv_t cd" "char ** restrict src" "size_t * restrict srcleft" "char ** restrict dst" "size_t * restrict dstleft"
|
2003-07-04 10:05:28 +04:00
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn iconv_open
|
|
|
|
function opens a converter from the codeset
|
|
|
|
.Fa srcname
|
|
|
|
to the codeset
|
|
|
|
.Fa dstname
|
|
|
|
and returns its descriptor.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn iconv_close
|
2003-07-04 11:44:19 +04:00
|
|
|
function closes the specified converter
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa cd .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn iconv
|
2003-07-04 11:44:19 +04:00
|
|
|
function converts the string in the buffer
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *src
|
2003-07-04 11:44:19 +04:00
|
|
|
of length
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *srcleft
|
2003-07-04 11:44:19 +04:00
|
|
|
bytes and stores the converted string in the buffer
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *dst
|
2003-07-04 11:44:19 +04:00
|
|
|
of size
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *dstleft
|
|
|
|
bytes.
|
|
|
|
After calling
|
|
|
|
.Fn iconv ,
|
2003-07-04 11:44:19 +04:00
|
|
|
the values pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa src ,
|
|
|
|
.Fa srcleft ,
|
2003-07-04 11:44:19 +04:00
|
|
|
.Fa dst ,
|
2003-07-04 10:05:28 +04:00
|
|
|
and
|
|
|
|
.Fa dstleft
|
2003-07-04 11:44:19 +04:00
|
|
|
are updated as follows:
|
2003-07-04 10:05:28 +04:00
|
|
|
.Bl -tag -width 01234567
|
|
|
|
.It *src
|
|
|
|
Pointer to the byte just after the last character fetched.
|
|
|
|
.It *srcleft
|
2003-07-04 11:44:19 +04:00
|
|
|
Number of remaining bytes in the source buffer.
|
2003-07-04 10:05:28 +04:00
|
|
|
.It *dst
|
|
|
|
Pointer to the byte just after the last character stored.
|
2003-07-05 20:54:23 +04:00
|
|
|
.It *dstleft
|
2003-07-04 11:44:19 +04:00
|
|
|
Number of remainder bytes in the destination buffer.
|
2003-07-04 10:05:28 +04:00
|
|
|
.El
|
|
|
|
.Pp
|
2003-07-04 11:44:19 +04:00
|
|
|
If the string pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *src
|
2003-07-04 11:44:19 +04:00
|
|
|
contains a byte sequence which is not a valid character in the source
|
2003-07-04 10:05:28 +04:00
|
|
|
codeset, the conversion stops just after the last successful conversion.
|
2003-07-04 11:44:19 +04:00
|
|
|
If the output buffer is too small to store the converted
|
2003-07-04 10:05:28 +04:00
|
|
|
character, the conversion also stops in the same way.
|
2003-07-04 11:44:19 +04:00
|
|
|
In these cases, the values pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa src ,
|
|
|
|
.Fa srcleft ,
|
2003-07-04 11:44:19 +04:00
|
|
|
.Fa dst ,
|
2003-07-04 10:05:28 +04:00
|
|
|
and
|
|
|
|
.Fa dstleft
|
2003-07-04 11:44:19 +04:00
|
|
|
are updated to the state just after the last successful conversion.
|
2003-07-04 10:05:28 +04:00
|
|
|
.Pp
|
2003-07-04 11:44:19 +04:00
|
|
|
If the string pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *src
|
2004-01-24 18:33:43 +03:00
|
|
|
contains a character which is valid under the source codeset but
|
2003-07-04 10:05:28 +04:00
|
|
|
can not be converted to the destination codeset,
|
2003-07-04 11:44:19 +04:00
|
|
|
the character is replaced by an
|
|
|
|
.Dq invalid character
|
|
|
|
which depends on the destination codeset, e.g.,
|
|
|
|
.Sq \&? ,
|
|
|
|
and the conversion is continued.
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv
|
2003-07-04 11:44:19 +04:00
|
|
|
returns the number of such
|
|
|
|
.Dq invalid conversions .
|
2003-07-04 10:05:28 +04:00
|
|
|
.Pp
|
2003-07-04 11:44:19 +04:00
|
|
|
There are two special cases of
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv :
|
|
|
|
.Bl -tag -width 0123
|
2003-09-01 10:16:13 +04:00
|
|
|
.It "src == NULL || *src == NULL"
|
2003-09-01 19:40:46 +04:00
|
|
|
.\"
|
2003-09-01 10:16:13 +04:00
|
|
|
If the source and/or destination codesets are stateful,
|
|
|
|
.Fn iconv
|
|
|
|
places these into their initial state.
|
|
|
|
.Pp
|
|
|
|
If both
|
|
|
|
.Fa dst
|
|
|
|
and
|
|
|
|
.Fa *dst
|
2004-01-24 18:33:43 +03:00
|
|
|
are
|
2003-09-01 19:40:46 +04:00
|
|
|
.No non- Ns Dv NULL ,
|
2003-09-01 10:16:13 +04:00
|
|
|
.Fn iconv
|
|
|
|
stores the shift sequence for the destination switching to the initial state
|
|
|
|
in the buffer pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *dst .
|
2003-07-05 21:34:55 +04:00
|
|
|
The buffer size is specified by the value pointed to by
|
2003-07-05 20:54:23 +04:00
|
|
|
.Fa dstleft
|
2003-07-05 21:34:55 +04:00
|
|
|
as above.
|
2003-07-05 20:54:23 +04:00
|
|
|
.Fn iconv
|
|
|
|
will fail if the buffer is too small to store the shift sequence.
|
2003-09-01 10:16:13 +04:00
|
|
|
.Pp
|
|
|
|
On the other hand,
|
|
|
|
.Fa dst
|
|
|
|
or
|
|
|
|
.Fa *dst
|
2003-09-01 19:40:46 +04:00
|
|
|
may be
|
|
|
|
.Dv NULL .
|
|
|
|
In this case, the shift sequence for the destination switching
|
2003-09-01 10:16:13 +04:00
|
|
|
to the initial state is discarded.
|
2003-07-04 10:05:28 +04:00
|
|
|
.El
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh RETURN VALUES
|
2003-07-04 11:44:19 +04:00
|
|
|
Upon successful completion of
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv_open ,
|
2003-07-04 11:44:19 +04:00
|
|
|
it returns a conversion descriptor.
|
|
|
|
Otherwise,
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv_open
|
2003-07-04 11:44:19 +04:00
|
|
|
returns (iconv_t)\-1 and sets errno to indicate the error.
|
2003-07-04 10:05:28 +04:00
|
|
|
.Pp
|
2003-07-04 11:44:19 +04:00
|
|
|
Upon successful completion of
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv_close ,
|
|
|
|
it returns 0.
|
|
|
|
Otherwise,
|
|
|
|
.Fn iconv_close
|
2003-07-04 11:44:19 +04:00
|
|
|
returns \-1 and sets errno to indicate the error.
|
2003-07-04 10:05:28 +04:00
|
|
|
.Pp
|
2003-07-04 11:44:19 +04:00
|
|
|
Upon successful completion of
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fn iconv ,
|
2003-07-04 11:44:19 +04:00
|
|
|
it returns the number of
|
|
|
|
.Dq invalid
|
|
|
|
conversions.
|
2003-07-04 10:05:28 +04:00
|
|
|
Otherwise,
|
|
|
|
.Fn iconv
|
2003-07-04 11:44:19 +04:00
|
|
|
returns (size_t)\-1 and sets errno to indicate the error.
|
2003-07-04 10:05:28 +04:00
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh ERRORS
|
|
|
|
The
|
|
|
|
.Fn iconv_open
|
2004-01-24 18:33:43 +03:00
|
|
|
function may cause an error in the following cases:
|
2003-07-04 10:05:28 +04:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er ENOMEM
|
|
|
|
Memory is exhausted.
|
|
|
|
.It Bq Er EINVAL
|
|
|
|
There is no converter specified by
|
|
|
|
.Fa srcname
|
|
|
|
and
|
|
|
|
.Fa dstname .
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn iconv_close
|
2004-01-24 18:33:43 +03:00
|
|
|
function may cause an error in the following case:
|
2003-07-04 10:05:28 +04:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EBADF
|
|
|
|
The conversion descriptor specified by
|
|
|
|
.Fa cd
|
|
|
|
is invalid.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn iconv
|
2004-01-24 18:33:43 +03:00
|
|
|
function may cause an error in the following cases:
|
2003-07-04 10:05:28 +04:00
|
|
|
.Bl -tag -width Er
|
|
|
|
.It Bq Er EBADF
|
|
|
|
The conversion descriptor specified by
|
|
|
|
.Fa cd
|
|
|
|
is invalid.
|
|
|
|
.It Bq Er EILSEQ
|
2003-07-04 11:44:19 +04:00
|
|
|
The string pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *src
|
2003-07-04 11:44:19 +04:00
|
|
|
contains a byte sequence which does not describe a valid character of
|
2003-07-04 10:05:28 +04:00
|
|
|
the source codeset.
|
|
|
|
.It Bq Er E2BIG
|
2003-07-04 11:44:19 +04:00
|
|
|
The output buffer pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *dst
|
|
|
|
is too small to store the result string.
|
|
|
|
.It Bq Er EINVAL
|
2003-07-04 11:44:19 +04:00
|
|
|
The string pointed to by
|
2003-07-04 10:05:28 +04:00
|
|
|
.Fa *src
|
2003-07-04 11:44:19 +04:00
|
|
|
terminates with an incomplete character or shift sequence.
|
2003-07-04 10:05:28 +04:00
|
|
|
.El
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr iconv 1
|
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh STANDARDS
|
|
|
|
.Fn iconv_open ,
|
2003-07-04 11:44:19 +04:00
|
|
|
.Fn iconv_close ,
|
2003-07-04 10:05:28 +04:00
|
|
|
and
|
|
|
|
.Fn iconv
|
|
|
|
conform to
|
|
|
|
.St -p1003.1-2001 .
|
2003-07-04 11:44:19 +04:00
|
|
|
.\" ----------------------------------------------------------------------
|
|
|
|
.Sh BUGS
|
|
|
|
If
|
|
|
|
.Fn iconv
|
|
|
|
is aborted due to the occurrence of some error,
|
|
|
|
the
|
|
|
|
.Dq invalid conversion
|
|
|
|
count mentioned above is unfortunately lost.
|