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