xref: /netbsd/lib/libc/locale/mbstowcs.3 (revision bf9ec67e)
1.\" $NetBSD: mbstowcs.3,v 1.3 2002/03/25 20:01:22 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 3, 2002
28.Dt MBSTOWCS 3
29.Os
30.\" ----------------------------------------------------------------------
31.Sh NAME
32.Nm mbstowcs
33.Nd converts a multibyte character string to a wide character string
34.\" ----------------------------------------------------------------------
35.Sh LIBRARY
36.Lb libc
37.\" ----------------------------------------------------------------------
38.Sh SYNOPSIS
39.Fd #include \*[Lt]stdlib.h\*[Gt]
40.Ft size_t
41.Fn mbstowcs "wchar_t * restrict pwcs" "const char * restrict s" "size_t n"
42.\" ----------------------------------------------------------------------
43.Sh DESCRIPTION
44The
45.Fn mbstowcs
46converts a null-terminated multibyte character string pointed by
47.Fa s
48to the corresponding wide character string and stores it to the array
49pointed by
50.Fa pwcs .
51This function may modify the first at most
52.Fa n
53elements of the array pointed by
54.Fa pwcs .
55Each characters will be converted as if
56.Xr mbtowc 3
57is continuously called, except the internal state of
58.Xr mbtowc 3
59will not be affected.
60.Pp
61For state-dependent encoding, the
62.Fn mbstowcs
63implies the multibyte character string pointed by
64.Fa s
65always to begin with an initial state.
66.Pp
67There are special cases:
68.Bl -tag -width 012345678901
69.It pwcs == NULL
70The
71.Fn mbstowcs
72returns the number of elements to store the whole wide character string
73corresponding to the multibyte character string pointed by
74.Fa s .
75In this case,
76.Fa n
77is ignored.
78.It s == NULL
79undefined (may causes the program to crash).
80.El
81.\" ----------------------------------------------------------------------
82.Sh RETURN VALUES
83The
84.Fn mbstowcs
85returns:
86.Bl -tag -width 012345678901
87.It 0 or positive
88Number of elements stored to the array pointed by
89.Fa pwcs .
90There is no cases that the value returned is greater than
91.Fa n
92(unless
93.Fa pwcs
94is a null pointer) or the value of MB_CUR_MAX macro.
95If the return value is equal to
96.Fa n ,
97the string pointed by
98.Fa pwcs
99will not be null-terminated.
100.It (size_t)-1
101.Fa s
102points the string containing invalid or incomplete multibyte character.
103The
104.Fn mbstowcs
105also sets errno to indicate the error.
106.El
107.\" ----------------------------------------------------------------------
108.Sh ERRORS
109The
110.Fn mbstowcs
111may causes an error in the following case:
112.Bl -tag -width Er
113.It Bq Er EILSEQ
114.Fa s
115points the string containing invalid or incomplete multibyte character.
116.El
117.\" ----------------------------------------------------------------------
118.Sh SEE ALSO
119.Xr mbtowc 3 ,
120.Xr setlocale 3
121\" ----------------------------------------------------------------------
122.Sh STANDARDS
123The
124.Fn mbstowcs
125function conforms to
126.St -ansiC .
127The restrict qualifier is added at
128.St -isoC99 .
129