xref: /freebsd/lib/libc/locale/mbsrtowcs.3 (revision a90b9d0159070121c221b966469c3e36d912bf82)
1.\" Copyright (c) 2002-2004 Tim J. Robbins
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.Dd August 7, 2020
25.Dt MBSRTOWCS 3
26.Os
27.Sh NAME
28.Nm mbsrtowcs ,
29.Nm mbsnrtowcs
30.Nd "convert a character string to a wide-character string (restartable)"
31.Sh LIBRARY
32.Lb libc
33.Sh SYNOPSIS
34.In wchar.h
35.Ft size_t
36.Fo mbsrtowcs
37.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t len"
38.Fa "mbstate_t * restrict ps"
39.Fc
40.Ft size_t
41.Fo mbsnrtowcs
42.Fa "wchar_t * restrict dst" "const char ** restrict src" "size_t nms"
43.Fa "size_t len" "mbstate_t * restrict ps"
44.Fc
45.Sh DESCRIPTION
46The
47.Fn mbsrtowcs
48function converts a sequence of multibyte characters pointed to indirectly by
49.Fa src
50into a sequence of corresponding wide characters and stores at most
51.Fa len
52of them in the
53.Vt wchar_t
54array pointed to by
55.Fa dst ,
56until it encounters a terminating null character
57.Pq Li '\e0' .
58.Pp
59If
60.Fa dst
61is
62.Dv NULL ,
63no characters are stored.
64.Pp
65If
66.Fa dst
67is not
68.Dv NULL ,
69the pointer pointed to by
70.Fa src
71is updated to point to the character after the one that conversion stopped at.
72If conversion stops because a null character is encountered,
73.Fa *src
74is set to
75.Dv NULL .
76.Pp
77The
78.Vt mbstate_t
79argument,
80.Fa ps ,
81is used to keep track of the shift state.
82If it is
83.Dv NULL ,
84.Fn mbsrtowcs
85uses an internal, static
86.Vt mbstate_t
87object, which is initialized to the initial conversion state
88at program startup.
89.Pp
90The
91.Fn mbsnrtowcs
92function behaves identically to
93.Fn mbsrtowcs ,
94except that conversion stops after reading at most
95.Fa nms
96bytes from the buffer pointed to by
97.Fa src .
98.Sh RETURN VALUES
99If successful, and
100.Fa dst
101is not NULL, the
102.Fn mbsrtowcs
103and
104.Fn mbsnrtowcs
105functions return the number of wide characters stored in
106the array pointed to by
107.Fa dst .
108.Pp
109If
110.Fa dst
111was NULL then the functions
112.Fn mbsrtowcs
113and
114.Fn mbsnrtowcs
115return the number of wide characters that would have been stored where
116.Fa dst
117points to an infinitely large array.
118.Pp
119If either one of the functions is not successful then
120.Po Vt size_t Pc Ns \-1
121is returned.
122.Sh ERRORS
123The
124.Fn mbsrtowcs
125and
126.Fn mbsnrtowcs
127functions will fail if:
128.Bl -tag -width Er
129.It Bq Er EILSEQ
130An invalid multibyte character sequence was encountered.
131.It Bq Er EINVAL
132The conversion state is invalid.
133.El
134.Sh SEE ALSO
135.Xr mbrtowc 3 ,
136.Xr mbstowcs 3 ,
137.Xr multibyte 3 ,
138.Xr wcsrtombs 3
139.Sh STANDARDS
140The
141.Fn mbsrtowcs
142function conforms to
143.St -isoC-99 .
144.Pp
145The
146.Fn mbsnrtowcs
147function is an extension to the standard.
148