Blame man3/mbsrtowcs.3

Packit 7cfc04
.\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
Packit 7cfc04
.\" This is free documentation; you can redistribute it and/or
Packit 7cfc04
.\" modify it under the terms of the GNU General Public License as
Packit 7cfc04
.\" published by the Free Software Foundation; either version 2 of
Packit 7cfc04
.\" the License, or (at your option) any later version.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" References consulted:
Packit 7cfc04
.\"   GNU glibc-2 source code and manual
Packit 7cfc04
.\"   Dinkumware C library reference http://www.dinkumware.com/
Packit 7cfc04
.\"   OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
Packit 7cfc04
.\"   ISO/IEC 9899:1999
Packit 7cfc04
.\"
Packit 7cfc04
.TH MBSRTOWCS 3  2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
mbsrtowcs \- convert a multibyte string to a wide-character string
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <wchar.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "size_t mbsrtowcs(wchar_t *" dest ", const char **" src ,
Packit 7cfc04
.BI "                  size_t " len ", mbstate_t *" ps );
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
If
Packit 7cfc04
.I dest
Packit 7cfc04
is not NULL, the
Packit 7cfc04
.BR mbsrtowcs ()
Packit 7cfc04
function converts the
Packit 7cfc04
multibyte string
Packit 7cfc04
.I *src
Packit 7cfc04
to a wide-character string starting at
Packit 7cfc04
.IR dest .
Packit 7cfc04
At most
Packit 7cfc04
.I len
Packit 7cfc04
wide characters are written to
Packit 7cfc04
.IR dest .
Packit 7cfc04
The shift state
Packit 7cfc04
.I *ps
Packit 7cfc04
is updated.
Packit 7cfc04
The conversion is effectively performed by repeatedly
Packit 7cfc04
calling
Packit 7cfc04
.I "mbrtowc(dest, *src, n, ps)"
Packit 7cfc04
where
Packit 7cfc04
.I n
Packit 7cfc04
is some
Packit 7cfc04
positive number, as long as this call succeeds, and then incrementing
Packit 7cfc04
.I dest
Packit 7cfc04
by one and
Packit 7cfc04
.I *src
Packit 7cfc04
by the number of bytes consumed.
Packit 7cfc04
The conversion can stop for three reasons:
Packit 7cfc04
.IP 1. 3
Packit 7cfc04
An invalid multibyte sequence has been encountered.
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is left pointing to the invalid multibyte sequence,
Packit 7cfc04
.I (size_t)\ \-1
Packit 7cfc04
is returned,
Packit 7cfc04
and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to
Packit 7cfc04
.BR EILSEQ .
Packit 7cfc04
.IP 2.
Packit 7cfc04
.I len
Packit 7cfc04
non-L\(aq\\0\(aq wide characters have been stored at
Packit 7cfc04
.IR dest .
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is left pointing to the next
Packit 7cfc04
multibyte sequence to be converted,
Packit 7cfc04
and the number of wide characters written to
Packit 7cfc04
.I dest
Packit 7cfc04
is returned.
Packit 7cfc04
.IP 3.
Packit 7cfc04
The multibyte string has been completely converted, including the
Packit 7cfc04
terminating null wide character (\(aq\\0\(aq), which has the side
Packit 7cfc04
effect of bringing back
Packit 7cfc04
.I *ps
Packit 7cfc04
to the
Packit 7cfc04
initial state.
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is set to NULL, and the number of wide
Packit 7cfc04
characters written to
Packit 7cfc04
.IR dest ,
Packit 7cfc04
excluding the terminating null wide character, is returned.
Packit 7cfc04
.PP
Packit 7cfc04
If
Packit 7cfc04
.IR dest
Packit 7cfc04
is NULL,
Packit 7cfc04
.I len
Packit 7cfc04
is ignored,
Packit 7cfc04
and the conversion proceeds as above,
Packit 7cfc04
except that the converted wide characters are not written out to memory,
Packit 7cfc04
and that no length limit exists.
Packit 7cfc04
.PP
Packit 7cfc04
In both of the above cases,
Packit 7cfc04
if
Packit 7cfc04
.I ps
Packit 7cfc04
is NULL, a static anonymous
Packit 7cfc04
state known only to the
Packit 7cfc04
.BR mbsrtowcs ()
Packit 7cfc04
function is used instead.
Packit 7cfc04
.PP
Packit 7cfc04
The programmer must ensure that there is room for at least
Packit 7cfc04
.I len
Packit 7cfc04
wide
Packit 7cfc04
characters at
Packit 7cfc04
.IR dest .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The
Packit 7cfc04
.BR mbsrtowcs ()
Packit 7cfc04
function returns the number of wide characters that make
Packit 7cfc04
up the converted part of the wide-character string, not including the
Packit 7cfc04
terminating null wide character.
Packit 7cfc04
If an invalid multibyte sequence was
Packit 7cfc04
encountered,
Packit 7cfc04
.I (size_t)\ \-1
Packit 7cfc04
is returned, and
Packit 7cfc04
.I errno
Packit 7cfc04
set to
Packit 7cfc04
.BR EILSEQ .
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lb lb lbw28
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR mbsrtowcs ()
Packit 7cfc04
T}	Thread safety	MT-Unsafe race:mbsrtowcs/!ps
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, C99.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The behavior of
Packit 7cfc04
.BR mbsrtowcs ()
Packit 7cfc04
depends on the
Packit 7cfc04
.B LC_CTYPE
Packit 7cfc04
category of the
Packit 7cfc04
current locale.
Packit 7cfc04
.PP
Packit 7cfc04
Passing NULL as
Packit 7cfc04
.I ps
Packit 7cfc04
is not multithread safe.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR iconv (3),
Packit 7cfc04
.BR mbrtowc (3),
Packit 7cfc04
.BR mbsinit (3),
Packit 7cfc04
.BR mbsnrtowcs (3),
Packit 7cfc04
.BR mbstowcs (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.