xref: /freebsd/lib/libc/locale/wcsrtombs.3 (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1.\" Copyright (c) 2002-2004 Tim J. Robbins
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd July 21, 2004
26.Dt WCSRTOMBS 3
27.Os
28.Sh NAME
29.Nm wcsrtombs ,
30.Nm wcsnrtombs
31.Nd "convert a wide-character string to a character string (restartable)"
32.Sh LIBRARY
33.Lb libc
34.Sh SYNOPSIS
35.In wchar.h
36.Ft size_t
37.Fo wcsrtombs
38.Fa "char * restrict dst" "const wchar_t ** restrict src"
39.Fa "size_t len" "mbstate_t * restrict ps"
40.Fc
41.Ft size_t
42.Fo wcsnrtombs
43.Fa "char * restrict dst" "const wchar_t ** restrict src" "size_t nwc"
44.Fa "size_t len" "mbstate_t * restrict ps"
45.Fc
46.Sh DESCRIPTION
47The
48.Fn wcsrtombs
49function converts a string of wide characters indirectly pointed to by
50.Fa src
51to a corresponding multibyte character string stored in the array
52pointed to by
53.Fa dst .
54No more than
55.Fa len
56bytes are written to
57.Fa dst .
58.Pp
59If
60.Fa dst
61is
62.Dv NULL ,
63no characters are stored.
64.Pp
65If
66.Fa dst
67is not
68.Dv NULL ,
69the pointer pointed to by
70.Fa src
71is updated to point to the character after the one that conversion stopped at.
72If conversion stops because a null character is encountered,
73.Fa *src
74is set to
75.Dv NULL .
76.Pp
77The
78.Vt mbstate_t
79argument,
80.Fa ps ,
81is used to keep track of the shift state.
82If it is
83.Dv NULL ,
84.Fn wcsrtombs
85uses an internal, static
86.Vt mbstate_t
87object, which is initialized to the initial conversion state
88at program startup.
89.Pp
90The
91.Fn wcsnrtombs
92function behaves identically to
93.Fn wcsrtombs ,
94except that conversion stops after reading at most
95.Fa nwc
96characters from the buffer pointed to by
97.Fa src .
98.Sh RETURN VALUES
99The
100.Fn wcsrtombs
101and
102.Fn wcsnrtombs
103functions return the number of bytes stored in
104the array pointed to by
105.Fa dst
106(not including any terminating null), if successful, otherwise it returns
107.Po Vt size_t Pc Ns \-1 .
108.Sh ERRORS
109The
110.Fn wcsrtombs
111and
112.Fn wcsnrtombs
113functions will fail if:
114.Bl -tag -width Er
115.It Bq Er EILSEQ
116An invalid wide character was encountered.
117.It Bq Er EINVAL
118The conversion state is invalid.
119.El
120.Sh SEE ALSO
121.Xr mbsrtowcs 3 ,
122.Xr wcrtomb 3 ,
123.Xr wcstombs 3
124.Sh STANDARDS
125The
126.Fn wcsrtombs
127function conforms to
128.St -isoC-99 .
129.Pp
130The
131.Fn wcsnrtombs
132function is an extension to the standard.
133