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