]> git.saurik.com Git - apple/libc.git/blame - locale/FreeBSD/mbrtowc.3
Libc-763.13.tar.gz
[apple/libc.git] / locale / FreeBSD / mbrtowc.3
CommitLineData
3d9156a7 1.\" Copyright (c) 2002-2004 Tim J. Robbins
9385eb3d
A
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.\"
3d9156a7 25.\" $FreeBSD: src/lib/libc/locale/mbrtowc.3,v 1.5 2004/06/30 19:32:41 ru Exp $
9385eb3d 26.\"
3d9156a7 27.Dd April 8, 2004
9385eb3d
A
28.Dt MBRTOWC 3
29.Os
30.Sh NAME
31.Nm mbrtowc
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
39.Fa "wchar_t * restrict pwc" "const char * restrict s" "size_t n"
40.Fa "mbstate_t * restrict ps"
41.Fc
42.Sh DESCRIPTION
43The
44.Fn mbrtowc
45function inspects at most
46.Fa n
47bytes pointed to by
48.Fa s
3d9156a7
A
49to determine the number of bytes needed to complete the next multibyte
50character.
51If a character can be completed, and
9385eb3d
A
52.Fa pwc
53is not
54.Dv NULL ,
3d9156a7 55the wide character which is represented by
9385eb3d 56.Fa s
3d9156a7 57is stored in the
9385eb3d
A
58.Vt wchar_t
59it points to.
60.Pp
61If
62.Fa s
63is
64.Dv NULL ,
65.Fn mbrtowc
66behaves as if
67.Fa pwc
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 ,
84.Fn mbrtowc
85uses an internal, static
86.Vt mbstate_t
3d9156a7
A
87object, which is initialized to the initial conversion state
88at program startup.
9385eb3d
A
89.Sh RETURN VALUES
90The
91.Fn mbrtowc
92functions returns:
93.Bl -tag -width indent
94.It 0
3d9156a7 95The next
9385eb3d 96.Fa n
3d9156a7 97or fewer bytes
9385eb3d
A
98represent the null wide character
99.Pq Li "L'\e0'" .
100.It >0
3d9156a7 101The next
9385eb3d 102.Fa n
3d9156a7 103or fewer bytes
9385eb3d
A
104represent a valid character,
105.Fn mbrtowc
3d9156a7 106returns the number of bytes used to complete the multibyte character.
9385eb3d 107.It Po Vt size_t Pc Ns \-2
3d9156a7 108The next
9385eb3d 109.Fa n
3d9156a7
A
110contribute to, but do not complete, a valid multibyte character sequence,
111and all
112.Fa n
113bytes have been processed.
9385eb3d 114.It Po Vt size_t Pc Ns \-1
3d9156a7
A
115An encoding error has occurred.
116The next
117.Fa n
118or fewer bytes do not contribute to a valid multibyte character.
9385eb3d
A
119.El
120.Sh ERRORS
121The
122.Fn mbrtowc
123function will fail if:
124.Bl -tag -width Er
9385eb3d
A
125.It Bq Er EILSEQ
126An invalid multibyte sequence was detected.
3d9156a7
A
127.It Bq Er EINVAL
128The conversion state is invalid.
9385eb3d
A
129.El
130.Sh SEE ALSO
131.Xr mbtowc 3 ,
3d9156a7 132.Xr multibyte 3 ,
9385eb3d
A
133.Xr setlocale 3 ,
134.Xr wcrtomb 3
135.Sh STANDARDS
136The
137.Fn mbrtowc
138function conforms to
139.St -isoC-99 .