xref: /netbsd-src/lib/libc/locale/wcsrtombs.3 (revision 67741c36810810c6763155043aea2dad579d6abe)
1*67741c36Srillig.\" $NetBSD: wcsrtombs.3,v 1.18 2024/10/13 14:56:30 rillig Exp $
28625ada8Stshiozak.\"
38625ada8Stshiozak.\" Copyright (c)2002 Citrus Project,
48625ada8Stshiozak.\" All rights reserved.
58625ada8Stshiozak.\"
68625ada8Stshiozak.\" Redistribution and use in source and binary forms, with or without
78625ada8Stshiozak.\" modification, are permitted provided that the following conditions
88625ada8Stshiozak.\" are met:
98625ada8Stshiozak.\" 1. Redistributions of source code must retain the above copyright
108625ada8Stshiozak.\"    notice, this list of conditions and the following disclaimer.
118625ada8Stshiozak.\" 2. Redistributions in binary form must reproduce the above copyright
128625ada8Stshiozak.\"    notice, this list of conditions and the following disclaimer in the
138625ada8Stshiozak.\"    documentation and/or other materials provided with the distribution.
148625ada8Stshiozak.\"
158625ada8Stshiozak.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
168625ada8Stshiozak.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
178625ada8Stshiozak.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
188625ada8Stshiozak.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
198625ada8Stshiozak.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
208625ada8Stshiozak.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
218625ada8Stshiozak.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
228625ada8Stshiozak.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
238625ada8Stshiozak.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
248625ada8Stshiozak.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
258625ada8Stshiozak.\" SUCH DAMAGE.
268625ada8Stshiozak.\"
27*67741c36Srillig.Dd October 13, 2024
288625ada8Stshiozak.Dt WCSRTOMBS 3
298625ada8Stshiozak.Os
308625ada8Stshiozak.\" ----------------------------------------------------------------------
318625ada8Stshiozak.Sh NAME
324dc858f2Swiz.Nm wcsrtombs ,
334dc858f2Swiz.Nm wcsnrtombs
343d3c5d42Swiz.Nd converts a wide-character string to a multibyte character string \
358625ada8Stshiozak(restartable)
368625ada8Stshiozak.\" ----------------------------------------------------------------------
378625ada8Stshiozak.Sh LIBRARY
388625ada8Stshiozak.Lb libc
398625ada8Stshiozak.\" ----------------------------------------------------------------------
408625ada8Stshiozak.Sh SYNOPSIS
4112d1d194Suwe.
428d8d8b95Stnozaki.In wchar.h
4312d1d194Suwe.
448625ada8Stshiozak.Ft size_t
4512d1d194Suwe.Fo wcsrtombs
4612d1d194Suwe.Fa "char * restrict s"
4712d1d194Suwe.Fa "const wchar_t ** restrict pwcs"
487a25a0c7Srillig.Fa "size_t n"
497a25a0c7Srillig.Fa "mbstate_t * restrict ps"
5012d1d194Suwe.Fc
5112d1d194Suwe.
52b3c7e95dSriastradh.Ft size_t
5312d1d194Suwe.Fo wcsnrtombs
5412d1d194Suwe.Fa "char * restrict s"
5512d1d194Suwe.Fa "const wchar_t ** restrict pwcs"
5612d1d194Suwe.Fa "size_t nwc"
5712d1d194Suwe.Fa "size_t n"
58*67741c36Srillig.Fa "mbstate_t * restrict ps"
5912d1d194Suwe.Fc
6012d1d194Suwe.
618625ada8Stshiozak.\" ----------------------------------------------------------------------
628625ada8Stshiozak.Sh DESCRIPTION
638625ada8StshiozakThe
648625ada8Stshiozak.Fn wcsrtombs
654dc858f2Swizfunction converts the NUL-terminated wide-character string indirectly
66b3c7e95dSriastradhpointed to by
678625ada8Stshiozak.Fa pwcs
688625ada8Stshiozakto the corresponding multibyte character string,
69cef0afe9Swizand stores it in the array pointed to by
708625ada8Stshiozak.Fa s .
719f64fab4SwizThe conversion stops due to the following reasons:
728625ada8Stshiozak.Bl -bullet
738625ada8Stshiozak.It
744dc858f2SwizThe conversion reaches a NUL wide character.
754dc858f2SwizIn this case, the NUL wide character is also converted.
768625ada8Stshiozak.It
778625ada8StshiozakThe
788625ada8Stshiozak.Fn wcsrtombs
798625ada8Stshiozakhas already stored
808625ada8Stshiozak.Fa n
81cef0afe9Swizbytes in the array pointed to by
828625ada8Stshiozak.Fa s .
838625ada8Stshiozak.It
848625ada8StshiozakThe conversion encounters an invalid character.
858625ada8Stshiozak.El
868625ada8Stshiozak.Pp
87be85fac5SjmmvEach character will be converted as if
888625ada8Stshiozak.Xr wcrtomb 3
898625ada8Stshiozakis continuously called, except the internal state of
908625ada8Stshiozak.Xr wcrtomb 3
918625ada8Stshiozakwill not be affected.
928625ada8Stshiozak.Pp
938625ada8StshiozakAfter conversion,
948625ada8Stshiozakif
958625ada8Stshiozak.Fa s
964dc858f2Swizis not a NULL pointer, the pointer object pointed to by
978625ada8Stshiozak.Fa pwcs
984dc858f2Swizis a NULL pointer
994dc858f2Swiz.Pq if the conversion is stopped due to reaching a NUL wide character
10012d1d194Suweor points to the first byte of the character just after the last
10112d1d194Suwecharacter converted.
1028625ada8Stshiozak.Pp
1038625ada8StshiozakIf
1048625ada8Stshiozak.Fa s
1054dc858f2Swizis not a NULL pointer and the conversion is stopped due to reaching
1064dc858f2Swiza NUL wide character,
1078625ada8Stshiozak.Fn wcsrtombs
108cef0afe9Swizplaces the state object pointed to by
1098625ada8Stshiozak.Fa ps
1108625ada8Stshiozakto an initial state after the conversion is taken place.
1118625ada8Stshiozak.Pp
1124dc858f2SwizThe behavior of
1138625ada8Stshiozak.Fn wcsrtombs
114cef0afe9Swizis affected by the
115cef0afe9Swiz.Dv LC_CTYPE
116cef0afe9Swizcategory of the current locale.
1178625ada8Stshiozak.Pp
118cef0afe9SwizThese are the special cases:
11912d1d194Suwe.Bl -tag -width Li
12012d1d194Suwe.It Li "s == NULL"
1218625ada8Stshiozak.Fn wcsrtombs
1228625ada8Stshiozakreturns the number of bytes to store the whole multibyte character string
1233d3c5d42Swizcorresponding to the wide-character string pointed to by
124de5444e8Syamt.Fa pwcs ,
1254dc858f2Swiznot including the terminating NUL byte.
1263225ede1SwizIn this case,
1278625ada8Stshiozak.Fa n
1288625ada8Stshiozakis ignored.
12912d1d194Suwe.It Li "pwcs == NULL || *pwcs == NULL"
130cef0afe9SwizUndefined (may cause the program to crash).
13112d1d194Suwe.It Li "ps == NULL"
1328625ada8Stshiozak.Fn wcsrtombs
1338625ada8Stshiozakuses its own internal state object to keep the conversion state,
1348625ada8Stshiozakinstead of
1358625ada8Stshiozak.Fa ps
1368625ada8Stshiozakmentioned in this manual page.
1378625ada8Stshiozak.Pp
138cef0afe9SwizCalling any other functions in
1398625ada8Stshiozak.Lb libc
140cef0afe9Swiznever changes the internal
141cef0afe9Swizstate of
1428625ada8Stshiozak.Fn wcsrtombs ,
143cef0afe9Swizwhich is initialized at startup time of the program.
1448625ada8Stshiozak.El
145b3c7e95dSriastradh.Pp
146b3c7e95dSriastradhThe
147b3c7e95dSriastradh.Fn wcsnrtombs
148b3c7e95dSriastradhfunction behaves identically to
149b3c7e95dSriastradh.Fn wcsrtombs ,
150b3c7e95dSriastradhexcept that the conversion stops after reading at most
151b3c7e95dSriastradh.Fa nwc
152b3c7e95dSriastradhcharacters from the buffer pointed to by
153b3c7e95dSriastradh.Fa pwcs .
1548625ada8Stshiozak.\" ----------------------------------------------------------------------
1558625ada8Stshiozak.Sh RETURN VALUES
156b3c7e95dSriastradhThe
1578625ada8Stshiozak.Fn wcsrtombs
158b3c7e95dSriastradhand
159b3c7e95dSriastradh.Fn wcsnrtombs
160b3c7e95dSriastradhfunctions return:
16112d1d194Suwe.Bl -tag -width Li
16212d1d194Suwe.It Li 0 , No or positive
163cef0afe9SwizNumber of bytes stored in the array pointed to by
1648625ada8Stshiozak.Fa s ,
1654dc858f2Swizexcept for a NUL byte.
166cef0afe9SwizThere are no cases that the value returned is greater than
1678625ada8Stshiozak.Fa n
16812d1d194Suwe.Po
16912d1d194Suweunless
1708625ada8Stshiozak.Fa s
1714dc858f2Swizis a NULL pointer
17212d1d194Suwe.Pc .
1738625ada8StshiozakIf the return value is equal to
1748625ada8Stshiozak.Fa n ,
175cef0afe9Swizthe string pointed to by
1768625ada8Stshiozak.Fa s
1774dc858f2Swizwill not be NUL-terminated.
17812d1d194Suwe.It Li "(size_t)-1"
1798625ada8Stshiozak.Fa pwcs
180cef0afe9Swizpoints to a string containing an invalid wide character.
1818625ada8StshiozakThe
1828625ada8Stshiozak.Fn wcsrtombs
183cef0afe9Swizalso sets
184cef0afe9Swiz.Va errno
185cef0afe9Swizto indicate the error.
1868625ada8Stshiozak.El
1878625ada8Stshiozak.\" ----------------------------------------------------------------------
1888625ada8Stshiozak.Sh ERRORS
189b3c7e95dSriastradhThe
1908625ada8Stshiozak.Fn wcsrtombs
191b3c7e95dSriastradhand
192b3c7e95dSriastradh.Fn wcsnrtombs
193b3c7e95dSriastradhfunctions may fail with the following errors:
1948625ada8Stshiozak.Bl -tag -width Er
1958625ada8Stshiozak.It Bq Er EILSEQ
1968625ada8Stshiozak.Fa pwcs
197cef0afe9Swizpoints to a string containing an invalid wide character.
198b3c7e95dSriastradh.It Bq Er EINVAL
199b3c7e95dSriastradh.Fa ps
20012d1d194Suwepoints to an invalid or uninitialized
20112d1d194Suwe.Vt mbstate_t
20212d1d194Suweobject.
2038625ada8Stshiozak.El
2048625ada8Stshiozak.\" ----------------------------------------------------------------------
2058625ada8Stshiozak.Sh SEE ALSO
2068625ada8Stshiozak.Xr setlocale 3 ,
2079f64fab4Swiz.Xr wcrtomb 3 ,
2089f64fab4Swiz.Xr wcstombs 3
2098625ada8Stshiozak.\" ----------------------------------------------------------------------
2108625ada8Stshiozak.Sh STANDARDS
2118625ada8StshiozakThe
2128625ada8Stshiozak.Fn wcsrtombs
2138625ada8Stshiozakfunction conforms to
2148625ada8Stshiozak.St -ansiC .
215b3c7e95dSriastradhThe
216b3c7e95dSriastradh.Li restrict
217b3c7e95dSriastradhqualifier was added by
218dca9ccd3Swiz.St -isoC-99 .
219b3c7e95dSriastradh.Pp
220b3c7e95dSriastradhThe
221b3c7e95dSriastradh.Fn wcsnrtombs
222b3c7e95dSriastradhfunction conforms to
223b3c7e95dSriastradh.St -p1003.1-2008 .
224