Deleted Added
full compact
mbrtowc.3 (216756) mbrtowc.3 (250883)
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.

--- 8 unchanged lines hidden (view full) ---

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.\"
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.

--- 8 unchanged lines hidden (view full) ---

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.\" $FreeBSD: head/lib/libc/locale/mbrtowc.3 216756 2010-12-28 10:08:50Z uqs $
25.\" $FreeBSD: head/lib/libc/locale/mbrtowc.3 250883 2013-05-21 19:59:37Z ed $
26.\"
26.\"
27.Dd April 8, 2004
27.Dd May 21, 2013
28.Dt MBRTOWC 3
29.Os
30.Sh NAME
28.Dt MBRTOWC 3
29.Os
30.Sh NAME
31.Nm mbrtowc
31.Nm mbrtowc ,
32.Nm mbrtoc16 ,
33.Nm mbrtoc32
32.Nd "convert a character to a wide-character code (restartable)"
33.Sh LIBRARY
34.Lb libc
35.Sh SYNOPSIS
36.In wchar.h
37.Ft size_t
38.Fo mbrtowc
34.Nd "convert a character to a wide-character code (restartable)"
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In wchar.h
39.Ft size_t
40.Fo mbrtowc
39.Fa "wchar_t * restrict pwc" "const char * restrict s" "size_t n"
41.Fa "wchar_t * restrict pc" "const char * restrict s" "size_t n"
40.Fa "mbstate_t * restrict ps"
41.Fc
42.Fa "mbstate_t * restrict ps"
43.Fc
44.In uchar.h
45.Ft size_t
46.Fo mbrtoc16
47.Fa "char16_t * restrict pc" "const char * restrict s" "size_t n"
48.Fa "mbstate_t * restrict ps"
49.Fc
50.Ft size_t
51.Fo mbrtoc32
52.Fa "char32_t * restrict pc" "const char * restrict s" "size_t n"
53.Fa "mbstate_t * restrict ps"
54.Fc
42.Sh DESCRIPTION
43The
55.Sh DESCRIPTION
56The
44.Fn mbrtowc
45function inspects at most
57.Fn mbrtowc ,
58.Fn mbrtoc16
59and
60.Fn mbrtoc32
61functions inspect at most
46.Fa n
47bytes pointed to by
48.Fa s
49to determine the number of bytes needed to complete the next multibyte
50character.
51If a character can be completed, and
62.Fa n
63bytes pointed to by
64.Fa s
65to determine the number of bytes needed to complete the next multibyte
66character.
67If a character can be completed, and
52.Fa pwc
68.Fa pc
53is not
54.Dv NULL ,
55the wide character which is represented by
56.Fa s
57is stored in the
69is not
70.Dv NULL ,
71the wide character which is represented by
72.Fa s
73is stored in the
58.Vt wchar_t
74.Vt wchar_t ,
75.Vt char16_t
76or
77.Vt char32_t
59it points to.
60.Pp
61If
62.Fa s
63is
64.Dv NULL ,
78it points to.
79.Pp
80If
81.Fa s
82is
83.Dv NULL ,
65.Fn mbrtowc
66behaves as if
67.Fa pwc
84these functions behave as if
85.Fa pc
68was
69.Dv NULL ,
70.Fa s
71was an empty string
72.Pq Qq
73and
74.Fa n
75was 1.
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 ,
86was
87.Dv NULL ,
88.Fa s
89was an empty string
90.Pq Qq
91and
92.Fa n
93was 1.
94.Pp
95The
96.Vt mbstate_t
97argument,
98.Fa ps ,
99is used to keep track of the shift state.
100If it is
101.Dv NULL ,
84.Fn mbrtowc
85uses an internal, static
102these functions use an internal, static
86.Vt mbstate_t
87object, which is initialized to the initial conversion state
88at program startup.
103.Vt mbstate_t
104object, which is initialized to the initial conversion state
105at program startup.
106.Pp
107As a single
108.Vt char16_t
109is not large enough to represent certain multibyte characters, the
110.Fn mbrtoc16
111function may need to be invoked multiple times to convert a single
112multibyte character sequence.
89.Sh RETURN VALUES
90The
113.Sh RETURN VALUES
114The
91.Fn mbrtowc
92functions returns:
115.Fn mbrtowc ,
116.Fn mbrtoc16
117and
118.Fn mbrtoc32
119functions return:
93.Bl -tag -width indent
94.It 0
95The next
96.Fa n
97or fewer bytes
98represent the null wide character
99.Pq Li "L'\e0'" .
100.It >0
101The next
102.Fa n
120.Bl -tag -width indent
121.It 0
122The next
123.Fa n
124or fewer bytes
125represent the null wide character
126.Pq Li "L'\e0'" .
127.It >0
128The next
129.Fa n
103or fewer bytes
104represent a valid character,
105.Fn mbrtowc
106returns the number of bytes used to complete the multibyte character.
130or fewer bytes represent a valid character, these functions
131return the number of bytes used to complete the multibyte character.
132.It Po Vt size_t Pc Ns \-1
133An encoding error has occurred.
134The next
135.Fa n
136or fewer bytes do not contribute to a valid multibyte character.
107.It Po Vt size_t Pc Ns \-2
108The next
109.Fa n
110contribute to, but do not complete, a valid multibyte character sequence,
111and all
112.Fa n
113bytes have been processed.
137.It Po Vt size_t Pc Ns \-2
138The next
139.Fa n
140contribute to, but do not complete, a valid multibyte character sequence,
141and all
142.Fa n
143bytes have been processed.
114.It Po Vt size_t Pc Ns \-1
115An encoding error has occurred.
116The next
117.Fa n
118or fewer bytes do not contribute to a valid multibyte character.
119.El
144.El
145.Pp
146The
147.Fn mbrtoc16
148function also returns:
149.Bl -tag -width indent
150.It Po Vt size_t Pc Ns \-3
151The next character resulting from a previous call has been stored.
152No bytes from the input have been consumed.
153.El
120.Sh ERRORS
121The
154.Sh ERRORS
155The
122.Fn mbrtowc
123function will fail if:
156.Fn mbrtowc ,
157.Fn mbrtoc16
158and
159.Fn mbrtoc32
160functions will fail if:
124.Bl -tag -width Er
125.It Bq Er EILSEQ
126An invalid multibyte sequence was detected.
127.It Bq Er EINVAL
128The conversion state is invalid.
129.El
130.Sh SEE ALSO
131.Xr mbtowc 3 ,
132.Xr multibyte 3 ,
133.Xr setlocale 3 ,
134.Xr wcrtomb 3
135.Sh STANDARDS
136The
161.Bl -tag -width Er
162.It Bq Er EILSEQ
163An invalid multibyte sequence was detected.
164.It Bq Er EINVAL
165The conversion state is invalid.
166.El
167.Sh SEE ALSO
168.Xr mbtowc 3 ,
169.Xr multibyte 3 ,
170.Xr setlocale 3 ,
171.Xr wcrtomb 3
172.Sh STANDARDS
173The
137.Fn mbrtowc
138function conforms to
139.St -isoC-99 .
174.Fn mbrtowc ,
175.Fn mbrtoc16
176and
177.Fn mbrtoc32
178functions conform to
179.St -isoC-2011 .