xref: /freebsd/lib/libc/locale/mbsrtowcs.3 (revision 90fb6afc5534df63f5c211d71e44263de646bce2)
18b810927STim J. Robbins.\" Copyright (c) 2002-2004 Tim J. Robbins
2e92a3d83STim J. Robbins.\" All rights reserved.
3e92a3d83STim J. Robbins.\"
4e92a3d83STim J. Robbins.\" Redistribution and use in source and binary forms, with or without
5e92a3d83STim J. Robbins.\" modification, are permitted provided that the following conditions
6e92a3d83STim J. Robbins.\" are met:
7e92a3d83STim J. Robbins.\" 1. Redistributions of source code must retain the above copyright
8e92a3d83STim J. Robbins.\"    notice, this list of conditions and the following disclaimer.
9e92a3d83STim J. Robbins.\" 2. Redistributions in binary form must reproduce the above copyright
10e92a3d83STim J. Robbins.\"    notice, this list of conditions and the following disclaimer in the
11e92a3d83STim J. Robbins.\"    documentation and/or other materials provided with the distribution.
12e92a3d83STim J. Robbins.\"
13e92a3d83STim J. Robbins.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14e92a3d83STim J. Robbins.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15e92a3d83STim J. Robbins.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16e92a3d83STim J. Robbins.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17e92a3d83STim J. Robbins.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18e92a3d83STim J. Robbins.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19e92a3d83STim J. Robbins.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20e92a3d83STim J. Robbins.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21e92a3d83STim J. Robbins.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22e92a3d83STim J. Robbins.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23e92a3d83STim J. Robbins.\" SUCH DAMAGE.
24e92a3d83STim J. Robbins.\"
25e92a3d83STim J. Robbins.\" $FreeBSD$
26*90fb6afcSGordon Bergling.Dd August 7, 2020
27e92a3d83STim J. Robbins.Dt MBSRTOWCS 3
28e92a3d83STim J. Robbins.Os
29e92a3d83STim J. Robbins.Sh NAME
301949a347STim J. Robbins.Nm mbsrtowcs ,
311949a347STim J. Robbins.Nm mbsnrtowcs
32e92a3d83STim J. Robbins.Nd "convert a character string to a wide-character string (restartable)"
33e92a3d83STim J. Robbins.Sh LIBRARY
34e92a3d83STim J. Robbins.Lb libc
35e92a3d83STim J. Robbins.Sh SYNOPSIS
36e92a3d83STim J. Robbins.In wchar.h
37e92a3d83STim J. Robbins.Ft size_t
38279062faSRuslan Ermilov.Fo mbsrtowcs
39279062faSRuslan Ermilov.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t len"
40279062faSRuslan Ermilov.Fa "mbstate_t * restrict ps"
41279062faSRuslan Ermilov.Fc
421949a347STim J. Robbins.Ft size_t
431949a347STim J. Robbins.Fo mbsnrtowcs
441949a347STim J. Robbins.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
451949a347STim J. Robbins.Fa "size_t len" "mbstate_t * restrict ps"
461949a347STim J. Robbins.Fc
47e92a3d83STim J. Robbins.Sh DESCRIPTION
48e92a3d83STim J. RobbinsThe
49e92a3d83STim J. Robbins.Fn mbsrtowcs
50e92a3d83STim J. Robbinsfunction converts a sequence of multibyte characters pointed to indirectly by
51e92a3d83STim J. Robbins.Fa src
52e92a3d83STim J. Robbinsinto a sequence of corresponding wide characters and stores at most
53e92a3d83STim J. Robbins.Fa len
54e92a3d83STim J. Robbinsof them in the
55279062faSRuslan Ermilov.Vt wchar_t
56e92a3d83STim J. Robbinsarray pointed to by
57e92a3d83STim J. Robbins.Fa dst ,
58279062faSRuslan Ermilovuntil it encounters a terminating null character
59279062faSRuslan Ermilov.Pq Li '\e0' .
60e92a3d83STim J. Robbins.Pp
61e92a3d83STim J. RobbinsIf
62e92a3d83STim J. Robbins.Fa dst
63e92a3d83STim J. Robbinsis
64e92a3d83STim J. Robbins.Dv NULL ,
65e92a3d83STim J. Robbinsno characters are stored.
66e92a3d83STim J. Robbins.Pp
67e92a3d83STim J. RobbinsIf
68e92a3d83STim J. Robbins.Fa dst
69e92a3d83STim J. Robbinsis not
70e92a3d83STim J. Robbins.Dv NULL ,
71e92a3d83STim J. Robbinsthe pointer pointed to by
72e92a3d83STim J. Robbins.Fa src
73e92a3d83STim J. Robbinsis updated to point to the character after the one that conversion stopped at.
74e92a3d83STim J. RobbinsIf conversion stops because a null character is encountered,
75279062faSRuslan Ermilov.Fa *src
76e92a3d83STim J. Robbinsis set to
77e92a3d83STim J. Robbins.Dv NULL .
78e92a3d83STim J. Robbins.Pp
79e92a3d83STim J. RobbinsThe
80279062faSRuslan Ermilov.Vt mbstate_t
81e92a3d83STim J. Robbinsargument,
82e92a3d83STim J. Robbins.Fa ps ,
83e92a3d83STim J. Robbinsis used to keep track of the shift state.
84e92a3d83STim J. RobbinsIf it is
85e92a3d83STim J. Robbins.Dv NULL ,
86e92a3d83STim J. Robbins.Fn mbsrtowcs
87e92a3d83STim J. Robbinsuses an internal, static
88279062faSRuslan Ermilov.Vt mbstate_t
898b810927STim J. Robbinsobject, which is initialized to the initial conversion state
908b810927STim J. Robbinsat program startup.
911949a347STim J. Robbins.Pp
921949a347STim J. RobbinsThe
931949a347STim J. Robbins.Fn mbsnrtowcs
941949a347STim J. Robbinsfunction behaves identically to
951949a347STim J. Robbins.Fn mbsrtowcs ,
961949a347STim J. Robbinsexcept that conversion stops after reading at most
971949a347STim J. Robbins.Fa nms
981949a347STim J. Robbinsbytes from the buffer pointed to by
991949a347STim J. Robbins.Fa src .
100e92a3d83STim J. Robbins.Sh RETURN VALUES
101*90fb6afcSGordon BerglingIf successful, and
102*90fb6afcSGordon Bergling.Fa dst
103*90fb6afcSGordon Berglingis not NULL, the
104e92a3d83STim J. Robbins.Fn mbsrtowcs
1051949a347STim J. Robbinsand
1061949a347STim J. Robbins.Fn mbsnrtowcs
1071949a347STim J. Robbinsfunctions return the number of wide characters stored in
108e92a3d83STim J. Robbinsthe array pointed to by
109*90fb6afcSGordon Bergling.Fa dst .
110*90fb6afcSGordon Bergling.Pp
111*90fb6afcSGordon BerglingIf
112e92a3d83STim J. Robbins.Fa dst
113*90fb6afcSGordon Berglingwas NULL then the functions
114*90fb6afcSGordon Bergling.Fn mbsrtowcs
115*90fb6afcSGordon Berglingand
116*90fb6afcSGordon Bergling.Fn mbsnrtowcs
117*90fb6afcSGordon Berglingreturn the number of wide characters that would have been stored where
118*90fb6afcSGordon Bergling.Fa dst
119*90fb6afcSGordon Berglingpoints to an infinitely large array.
120*90fb6afcSGordon Bergling.Pp
121*90fb6afcSGordon BerglingIf either one of the functions is not successful then
122*90fb6afcSGordon Bergling.Po Vt size_t Pc Ns \-1
123*90fb6afcSGordon Berglingis returned.
124e92a3d83STim J. Robbins.Sh ERRORS
125e92a3d83STim J. RobbinsThe
126e92a3d83STim J. Robbins.Fn mbsrtowcs
1271949a347STim J. Robbinsand
1281949a347STim J. Robbins.Fn mbsnrtowcs
1291949a347STim J. Robbinsfunctions will fail if:
130e92a3d83STim J. Robbins.Bl -tag -width Er
131e92a3d83STim J. Robbins.It Bq Er EILSEQ
132e92a3d83STim J. RobbinsAn invalid multibyte character sequence was encountered.
1338b810927STim J. Robbins.It Bq Er EINVAL
1348b810927STim J. RobbinsThe conversion state is invalid.
135e92a3d83STim J. Robbins.El
136e92a3d83STim J. Robbins.Sh SEE ALSO
137e92a3d83STim J. Robbins.Xr mbrtowc 3 ,
138e92a3d83STim J. Robbins.Xr mbstowcs 3 ,
1398b810927STim J. Robbins.Xr multibyte 3 ,
140e92a3d83STim J. Robbins.Xr wcsrtombs 3
141e92a3d83STim J. Robbins.Sh STANDARDS
142e92a3d83STim J. RobbinsThe
143e92a3d83STim J. Robbins.Fn mbsrtowcs
144e92a3d83STim J. Robbinsfunction conforms to
145e92a3d83STim J. Robbins.St -isoC-99 .
1461949a347STim J. Robbins.Pp
1471949a347STim J. RobbinsThe
1481949a347STim J. Robbins.Fn mbsnrtowcs
1491949a347STim J. Robbinsfunction is an extension to the standard.
150