xref: /openbsd/lib/libc/locale/wcsrtombs.3 (revision fc61954a)
1.\" $OpenBSD: wcsrtombs.3,v 1.5 2013/06/05 03:39:22 tedu Exp $
2.\" $NetBSD: wcsrtombs.3,v 1.6 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: June 5 2013 $
29.Dt WCSRTOMBS 3
30.Os
31.\" ----------------------------------------------------------------------
32.Sh NAME
33.Nm wcsrtombs ,
34.Nm wcsnrtombs
35.Nd converts a wide-character string to a multibyte character string \
36(restartable)
37.\" ----------------------------------------------------------------------
38.Sh SYNOPSIS
39.In wchar.h
40.Ft size_t
41.Fn wcsrtombs "const char * restrict dst" "const wchar_t ** restrict src" \
42"size_t len" "mbstate_t * restrict ps"
43.Ft size_t
44.Fn wcsnrtombs "const char * restrict dst" "const wchar_t ** restrict src" \
45"size_t nwc" "size_t len" "mbstate_t * restrict ps"
46.\" ----------------------------------------------------------------------
47.Sh DESCRIPTION
48The
49.Fn wcsrtombs
50function converts the wide-character string indirectly pointed to by
51.Fa src
52to the corresponding multibyte character string
53and stores it to the array pointed to by
54.Fa dst .
55The conversion stops due to the following reasons:
56.Bl -bullet
57.It
58The conversion reaches a null wide character.
59In this case, the null wide character is also converted.
60.It
61The conversion has already stored
62.Fa len
63bytes to the array pointed to by
64.Fa dst .
65.It
66The conversion encounters an invalid character.
67.El
68.Pp
69The
70.Fn wcsnrtombs
71function is equivalent to
72.Fn wcsrtombs
73except that it additionally stops the conversion after processing
74.Fa nwc
75wide characters.
76.Pp
77Each character will be converted as if
78.Xr wcrtomb 3
79is continuously called, except the internal state of
80.Xr wcrtomb 3
81will not be affected.
82.Pp
83After conversion,
84if
85.Fa dst
86is not a null pointer,
87the pointer object pointed to by
88.Fa src
89is a null pointer (if the conversion is stopped due to reaching a null wide character)
90or the address just past the last wide character processed.
91.Pp
92If
93.Fa dst
94is not a null pointer and the conversion is stopped due to reaching
95a null wide character,
96the state object pointed to by
97.Fa ps
98is set to an initial state after the conversion has taken place.
99.Pp
100The behaviour of the
101.Fn wcsrtombs
102and
103.Fn wcsnrtombs
104functions is affected by the
105.Dv LC_CTYPE
106category of the current locale.
107.Pp
108There are two special cases:
109.Bl -tag -width 012345678901
110.It "dst == NULL"
111The conversion takes place, but the resulting multibyte string is discarded.
112In this case, the pointer object pointed to by
113.Fa src
114is not modified and
115.Fa len
116is ignored.
117.It "ps == NULL"
118The
119.Fn wcsrtombs
120and
121.Fn wcsnrtombs
122functions use their own internal state objects to keep the conversion state,
123instead of
124.Fa ps
125as mentioned in this manual page.
126.Pp
127Calling any other functions in
128.Em libc
129never change these internal states,
130which are initialized at startup time of the program.
131.El
132.\" ----------------------------------------------------------------------
133.Sh RETURN VALUES
134The
135.Fn wcsrtombs
136and
137.Fn wcsnrtombs
138functions return:
139.Bl -tag -width 012345678901
140.It 0 or positive
141Number of bytes stored to the array pointed to by
142.Fa dst ,
143except for a null byte.
144There is no cases that the value returned is greater than
145.Fa len
146(unless
147.Fa dst
148is a null pointer).
149If the return value is equal to
150.Fa len ,
151the string pointed to by
152.Fa dst
153will not be null-terminated.
154.It (size_t)-1
155.Fa src
156points to the string containing invalid wide character.
157In this case,
158.Va errno
159is set to indicate the error.
160.El
161.\" ----------------------------------------------------------------------
162.Sh ERRORS
163The
164.Fn wcsrtombs
165and
166.Fn wcsnrtombs
167functions may return the following errors:
168.Bl -tag -width Er
169.It Bq Er EILSEQ
170.Fa src
171points to the string containing an invalid wide character.
172.It Bq Er EINVAL
173.Fa ps
174points to an invalid or uninitialized mbstate_t object.
175.El
176.\" ----------------------------------------------------------------------
177.Sh SEE ALSO
178.Xr setlocale 3 ,
179.Xr wcrtomb 3 ,
180.Xr wcstombs 3
181.\" ----------------------------------------------------------------------
182.Sh STANDARDS
183The
184.Fn wcsrtombs
185function conforms to
186.St -ansiC .
187The restrict qualifier is added at
188.\" .St -isoC99 .
189ISO/IEC 9899/AMD1:1995
190.Pq Dq ISO C99 .
191.Pp
192The
193.Fn wcsnrtombs
194function conforms to
195.St -p1003.1-2008 .
196