xref: /openbsd/lib/libc/locale/mbsrtowcs.3 (revision 898184e3)
1.\" $OpenBSD: mbsrtowcs.3,v 1.4 2012/06/07 19:47:40 matthew Exp $
2.\" $NetBSD: mbsrtowcs.3,v 1.6 2003/09/08 17:54:31 wiz Exp $
3.\"
4.\" Copyright (c)2002 Citrus Project,
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd $Mdocdate: June 7 2012 $
29.Dt MBSRTOWCS 3
30.Os
31.\" ----------------------------------------------------------------------
32.Sh NAME
33.Nm mbsrtowcs ,
34.Nm mbsnrtowcs
35.Nd converts a multibyte character string to a wide-character string \
36(restartable)
37.\" ----------------------------------------------------------------------
38.Sh SYNOPSIS
39.Fd #include <wchar.h>
40.Ft size_t
41.Fn mbsrtowcs "wchar_t * restrict dst" "const char ** restrict src" "size_t len" \
42"mbstate_t * restrict ps"
43.Ft size_t
44.Fn mbsnrtowcs "wchar_t * restrict dst" "const char ** restrict src" "size_t nmc" \
45"size_t len" "mbstate_t * restrict ps"
46.\" ----------------------------------------------------------------------
47.Sh DESCRIPTION
48The
49.Fn mbsrtowcs
50function converts the multibyte character string indirectly pointed to by
51.Fa src
52to the corresponding wide-character string and stores it in the
53array pointed to by
54.Fa dst .
55The conversion stops due to the following reasons:
56.Bl -bullet
57.It
58The conversion reaches a null byte.
59In this case, the null byte is also converted.
60.It
61The conversion has already stored
62.Fa len
63wide characters.
64.It
65The conversion encounters an invalid character.
66.El
67.Pp
68The
69.Fn mbsnrtowcs
70function is equivalent to
71.Fn mbsrtowcs
72except that it will additionally stop the conversion after processing
73.Fa nmc
74bytes.
75.Pp
76Each character is converted as if
77.Xr mbrtowc 3
78is continuously called.
79.Pp
80After conversion,
81if
82.Fa dst
83is not a null pointer,
84the pointer object pointed to by
85.Fa src
86is a null pointer (if the conversion is stopped due to reaching a null byte)
87or the address just past the last byte processed.
88.Pp
89If
90.Fa dst
91is not a
92null pointer and the conversion is stopped due to reaching a null byte,
93the state object pointed to by
94.Fa ps
95is set to an initial state after the conversion has taken place.
96.Pp
97The behaviour of the
98.Fn mbsrtowcs
99and
100.Fn mbsnrtowcs
101functions is affected by the
102.Dv LC_CTYPE
103category of the current locale.
104.Pp
105There are two special cases:
106.Bl -tag -width 012345678901
107.It "dst == NULL"
108The conversion takes place, but the resultant wide-character string
109is discarded.
110In this case, the pointer object pointed to by
111.Fa src
112is not modified and
113.Fa len
114is ignored.
115.It "ps == NULL"
116The
117.Fn mbsrtowcs
118and
119.Fn mbsnrtowcs
120functions use their own internal state objects to keep the conversion state,
121instead of
122.Fa ps
123as mentioned in this manual page.
124.Pp
125Calling any other functions in
126.Em libc
127never change these internal states,
128which are initialized at startup time of the program.
129.El
130.\" ----------------------------------------------------------------------
131.Sh RETURN VALUES
132The
133.Fn mbsrtowcs
134and
135.Fn mbsnrtowcs
136functions return:
137.Bl -tag -width 012345678901
138.It 0 or positive
139The value returned is the number of elements stored in the array pointed to by
140.Fa dst ,
141except for a terminating null wide character (if any).
142If
143.Fa dst
144is not null and the value returned is equal to
145.Fa len ,
146the wide-character string pointed to by
147.Fa dst
148is not null terminated.
149If
150.Fa dst
151is a null pointer, the value returned is the number of elements to contain
152the whole string converted, except for a terminating null wide character.
153.It (size_t)-1
154The array indirectly pointed to by
155.Fa src
156contains a byte sequence forming invalid character.
157In this case,
158.Va errno
159is set to indicate the error.
160.El
161.\" ----------------------------------------------------------------------
162.Sh ERRORS
163The
164.Fn mbsrtowcs
165and
166.Fn mbsnrtowcs
167functions may return the following errors:
168.Bl -tag -width Er
169.It Bq Er EILSEQ
170The pointer pointed to by
171.Fa src
172points to an invalid or incomplete multibyte character.
173.It Bq Er EINVAL
174.Fa ps
175points to an invalid or uninitialized mbstate_t object.
176.El
177.\" ----------------------------------------------------------------------
178.Sh SEE ALSO
179.Xr mbrtowc 3 ,
180.Xr mbstowcs 3 ,
181.Xr setlocale 3
182.\" ----------------------------------------------------------------------
183.Sh STANDARDS
184The
185.Fn mbsrtowcs
186function conforms to
187.\" .St -isoC-amd1 .
188ISO/IEC 9899/AMD1:1995
189.Pq Dq ISO C90, Amendment 1 .
190The restrict qualifier is added at
191.\" .St -isoC99 .
192ISO/IEC 9899/1999
193.Dq Pq ISO C99 .
194.Pp
195The
196.Fn mbsnrtowcs
197function conforms to
198.St -p1003.1-2008 .
199