Blame man3/wcsrtombs.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 WCSRTOMBS 3  2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
wcsrtombs \- convert a wide-character string to a multibyte string
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <wchar.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "size_t wcsrtombs(char *" dest ", const wchar_t **" 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,
Packit 7cfc04
the
Packit 7cfc04
.BR wcsrtombs ()
Packit 7cfc04
function converts
Packit 7cfc04
the wide-character string
Packit 7cfc04
.I *src
Packit 7cfc04
to a multibyte string starting at
Packit 7cfc04
.IR dest .
Packit 7cfc04
At most
Packit 7cfc04
.I len
Packit 7cfc04
bytes 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
.IR "wcrtomb(dest, *src, ps)" ,
Packit 7cfc04
as long as this call succeeds,
Packit 7cfc04
and then incrementing
Packit 7cfc04
.I dest
Packit 7cfc04
by the
Packit 7cfc04
number of bytes written and
Packit 7cfc04
.I *src
Packit 7cfc04
by one.
Packit 7cfc04
The conversion can stop for three reasons:
Packit 7cfc04
.IP 1. 3
Packit 7cfc04
A wide character has been encountered that can not be represented as a
Packit 7cfc04
multibyte sequence (according to the current locale).
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is left pointing to the invalid wide character,
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
The length limit forces a stop.
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is left pointing
Packit 7cfc04
to the next wide character to be converted,
Packit 7cfc04
and the number of bytes written to
Packit 7cfc04
.I dest
Packit 7cfc04
is returned.
Packit 7cfc04
.IP 3.
Packit 7cfc04
The wide-character string has been completely converted, including the
Packit 7cfc04
terminating null wide character (L\(aq\\0\(aq),
Packit 7cfc04
which has the side effect of bringing back
Packit 7cfc04
.I *ps
Packit 7cfc04
to the initial state.
Packit 7cfc04
In this case,
Packit 7cfc04
.I *src
Packit 7cfc04
is set to NULL, and the number
Packit 7cfc04
of bytes written to
Packit 7cfc04
.IR dest ,
Packit 7cfc04
excluding the terminating null byte (\(aq\\0\(aq),
Packit 7cfc04
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, except that the converted bytes
Packit 7cfc04
are not written out to memory, and that
Packit 7cfc04
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 wcsrtombs ()
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
bytes
Packit 7cfc04
at
Packit 7cfc04
.IR dest .
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The
Packit 7cfc04
.BR wcsrtombs ()
Packit 7cfc04
function returns
Packit 7cfc04
the number of bytes that make up the
Packit 7cfc04
converted part of multibyte sequence,
Packit 7cfc04
not including the terminating null byte.
Packit 7cfc04
If a wide character was encountered
Packit 7cfc04
which could not be converted,
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 wcsrtombs ()
Packit 7cfc04
T}	Thread safety	MT-Unsafe race:wcsrtombs/!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 wcsrtombs ()
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 mbsinit (3),
Packit 7cfc04
.BR wcrtomb (3),
Packit 7cfc04
.BR wcsnrtombs (3),
Packit 7cfc04
.BR wcstombs (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/.