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