xref: /freebsd/lib/libc/locale/mbsrtowcs.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.
24*90fb6afcSGordon Bergling.Dd August 7, 2020
25e92a3d83STim J. Robbins.Dt MBSRTOWCS 3
26e92a3d83STim J. Robbins.Os
27e92a3d83STim J. Robbins.Sh NAME
281949a347STim J. Robbins.Nm mbsrtowcs ,
291949a347STim J. Robbins.Nm mbsnrtowcs
30e92a3d83STim J. Robbins.Nd "convert a character string to a wide-character string (restartable)"
31e92a3d83STim J. Robbins.Sh LIBRARY
32e92a3d83STim J. Robbins.Lb libc
33e92a3d83STim J. Robbins.Sh SYNOPSIS
34e92a3d83STim J. Robbins.In wchar.h
35e92a3d83STim J. Robbins.Ft size_t
36279062faSRuslan Ermilov.Fo mbsrtowcs
37279062faSRuslan Ermilov.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t len"
38279062faSRuslan Ermilov.Fa "mbstate_t * restrict ps"
39279062faSRuslan Ermilov.Fc
401949a347STim J. Robbins.Ft size_t
411949a347STim J. Robbins.Fo mbsnrtowcs
421949a347STim J. Robbins.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
431949a347STim J. Robbins.Fa "size_t len" "mbstate_t * restrict ps"
441949a347STim J. Robbins.Fc
45e92a3d83STim J. Robbins.Sh DESCRIPTION
46e92a3d83STim J. RobbinsThe
47e92a3d83STim J. Robbins.Fn mbsrtowcs
48e92a3d83STim J. Robbinsfunction converts a sequence of multibyte characters pointed to indirectly by
49e92a3d83STim J. Robbins.Fa src
50e92a3d83STim J. Robbinsinto a sequence of corresponding wide characters and stores at most
51e92a3d83STim J. Robbins.Fa len
52e92a3d83STim J. Robbinsof them in the
53279062faSRuslan Ermilov.Vt wchar_t
54e92a3d83STim J. Robbinsarray pointed to by
55e92a3d83STim J. Robbins.Fa dst ,
56279062faSRuslan Ermilovuntil it encounters a terminating null character
57279062faSRuslan Ermilov.Pq Li '\e0' .
58e92a3d83STim J. Robbins.Pp
59e92a3d83STim J. RobbinsIf
60e92a3d83STim J. Robbins.Fa dst
61e92a3d83STim J. Robbinsis
62e92a3d83STim J. Robbins.Dv NULL ,
63e92a3d83STim J. Robbinsno characters are stored.
64e92a3d83STim J. Robbins.Pp
65e92a3d83STim J. RobbinsIf
66e92a3d83STim J. Robbins.Fa dst
67e92a3d83STim J. Robbinsis not
68e92a3d83STim J. Robbins.Dv NULL ,
69e92a3d83STim J. Robbinsthe pointer pointed to by
70e92a3d83STim J. Robbins.Fa src
71e92a3d83STim J. Robbinsis updated to point to the character after the one that conversion stopped at.
72e92a3d83STim J. RobbinsIf conversion stops because a null character is encountered,
73279062faSRuslan Ermilov.Fa *src
74e92a3d83STim J. Robbinsis set to
75e92a3d83STim J. Robbins.Dv NULL .
76e92a3d83STim J. Robbins.Pp
77e92a3d83STim J. RobbinsThe
78279062faSRuslan Ermilov.Vt mbstate_t
79e92a3d83STim J. Robbinsargument,
80e92a3d83STim J. Robbins.Fa ps ,
81e92a3d83STim J. Robbinsis used to keep track of the shift state.
82e92a3d83STim J. RobbinsIf it is
83e92a3d83STim J. Robbins.Dv NULL ,
84e92a3d83STim J. Robbins.Fn mbsrtowcs
85e92a3d83STim J. Robbinsuses an internal, static
86279062faSRuslan Ermilov.Vt mbstate_t
878b810927STim J. Robbinsobject, which is initialized to the initial conversion state
888b810927STim J. Robbinsat program startup.
891949a347STim J. Robbins.Pp
901949a347STim J. RobbinsThe
911949a347STim J. Robbins.Fn mbsnrtowcs
921949a347STim J. Robbinsfunction behaves identically to
931949a347STim J. Robbins.Fn mbsrtowcs ,
941949a347STim J. Robbinsexcept that conversion stops after reading at most
951949a347STim J. Robbins.Fa nms
961949a347STim J. Robbinsbytes from the buffer pointed to by
971949a347STim J. Robbins.Fa src .
98e92a3d83STim J. Robbins.Sh RETURN VALUES
99*90fb6afcSGordon BerglingIf successful, and
100*90fb6afcSGordon Bergling.Fa dst
101*90fb6afcSGordon Berglingis not NULL, the
102e92a3d83STim J. Robbins.Fn mbsrtowcs
1031949a347STim J. Robbinsand
1041949a347STim J. Robbins.Fn mbsnrtowcs
1051949a347STim J. Robbinsfunctions return the number of wide characters stored in
106e92a3d83STim J. Robbinsthe array pointed to by
107*90fb6afcSGordon Bergling.Fa dst .
108*90fb6afcSGordon Bergling.Pp
109*90fb6afcSGordon BerglingIf
110e92a3d83STim J. Robbins.Fa dst
111*90fb6afcSGordon Berglingwas NULL then the functions
112*90fb6afcSGordon Bergling.Fn mbsrtowcs
113*90fb6afcSGordon Berglingand
114*90fb6afcSGordon Bergling.Fn mbsnrtowcs
115*90fb6afcSGordon Berglingreturn the number of wide characters that would have been stored where
116*90fb6afcSGordon Bergling.Fa dst
117*90fb6afcSGordon Berglingpoints to an infinitely large array.
118*90fb6afcSGordon Bergling.Pp
119*90fb6afcSGordon BerglingIf either one of the functions is not successful then
120*90fb6afcSGordon Bergling.Po Vt size_t Pc Ns \-1
121*90fb6afcSGordon Berglingis returned.
122e92a3d83STim J. Robbins.Sh ERRORS
123e92a3d83STim J. RobbinsThe
124e92a3d83STim J. Robbins.Fn mbsrtowcs
1251949a347STim J. Robbinsand
1261949a347STim J. Robbins.Fn mbsnrtowcs
1271949a347STim J. Robbinsfunctions will fail if:
128e92a3d83STim J. Robbins.Bl -tag -width Er
129e92a3d83STim J. Robbins.It Bq Er EILSEQ
130e92a3d83STim J. RobbinsAn invalid multibyte character sequence was encountered.
1318b810927STim J. Robbins.It Bq Er EINVAL
1328b810927STim J. RobbinsThe conversion state is invalid.
133e92a3d83STim J. Robbins.El
134e92a3d83STim J. Robbins.Sh SEE ALSO
135e92a3d83STim J. Robbins.Xr mbrtowc 3 ,
136e92a3d83STim J. Robbins.Xr mbstowcs 3 ,
1378b810927STim J. Robbins.Xr multibyte 3 ,
138e92a3d83STim J. Robbins.Xr wcsrtombs 3
139e92a3d83STim J. Robbins.Sh STANDARDS
140e92a3d83STim J. RobbinsThe
141e92a3d83STim J. Robbins.Fn mbsrtowcs
142e92a3d83STim J. Robbinsfunction conforms to
143e92a3d83STim J. Robbins.St -isoC-99 .
1441949a347STim J. Robbins.Pp
1451949a347STim J. RobbinsThe
1461949a347STim J. Robbins.Fn mbsnrtowcs
1471949a347STim J. Robbinsfunction is an extension to the standard.
148