Report the nohistory, noshistory, and nouhistory flags, and allow them
[dragonfly.git] / lib / libc / locale / mbtowc.3
1 .\" $NetBSD: src/lib/libc/locale/mbtowc.3,v 1.6 2004/01/24 16:58:54 wiz Exp $
2 .\" $DragonFly: src/lib/libc/locale/mbtowc.3,v 1.1 2005/03/12 00:18:01 joerg 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 February 3, 2002
29 .Dt MBTOWC 3
30 .Os
31 .\" ----------------------------------------------------------------------
32 .Sh NAME
33 .Nm mbtowc
34 .Nd converts a multibyte character to a wide character
35 .\" ----------------------------------------------------------------------
36 .Sh LIBRARY
37 .Lb libc
38 .\" ----------------------------------------------------------------------
39 .Sh SYNOPSIS
40 .In stdlib.h
41 .Ft int
42 .Fn mbtowc "wchar_t * restrict pwc" "const char * restrict s" "size_t n"
43 .Sh DESCRIPTION
44 .Fn mbtowc
45 usually converts the multibyte character pointed to by
46 .Fa s
47 to a wide character, and stores it in the wchar_t object pointed to by
48 .Fa pwc
49 if
50 .Fa pwc
51 is non-null and
52 .Fa s
53 points to a valid character.
54 This function may inspect at most n bytes of the array beginning from
55 .Fa s .
56 .Pp
57 In state-dependent encodings,
58 .Fa s
59 may point to the special sequence bytes to change the shift-state.
60 Although such sequence bytes correspond to no individual
61 wide-character code,
62 .Fn mbtowc
63 changes its own state by the sequence bytes and treats them
64 as if they are a part of the subsequence multibyte character.
65 .Pp
66 Unlike
67 .Xr mbrtowc 3 ,
68 the first
69 .Fa n
70 bytes pointed to by
71 .Fa s
72 need to form an entire multibyte character.
73 Otherwise, this function causes an error.
74 .Pp
75 Calling any other functions in
76 .Lb libc
77 never changes the internal state of
78 .Fn mbtowc ,
79 except for calling
80 .Xr setlocale 3
81 with changing the
82 .Dv LC_CTYPE
83 category of the current locale.
84 Such
85 .Xr setlocale 3
86 call causes the internal state of this function to be indeterminate.
87 .Pp
88 The behaviour of
89 .Fn mbtowc
90 is affected by the
91 .Dv LC_CTYPE
92 category of the current locale.
93 .Pp
94 There are special cases:
95 .Bl -tag -width 012345678901
96 .It s == NULL
97 .Fn mbtowc
98 initializes its own internal state to an initial state, and
99 determines whether the current encoding is state-dependent.
100 This function returns 0 if the encoding is state-independent,
101 otherwise non-zero.
102 In this case,
103 .Fa pwc
104 is completely ignored.
105 .It pwc == NULL
106 .Fn mbtowc
107 executes the conversion as if
108 .Fa pwc
109 is non-null, but a result of the conversion is discarded.
110 .It n == 0
111 In this case,
112 the first
113 .Fa n
114 bytes of the array pointed to by
115 .Fa s
116 never form a complete character.
117 Thus, the
118 .Fn mbtowc
119 always fails.
120 .El
121 .\" ----------------------------------------------------------------------
122 .Sh RETURN VALUES
123 Normally, the
124 .Fn mbtowc
125 returns:
126 .Bl -tag -width 012345678901
127 .It 0
128 .Fa s
129 points to a null byte
130 .Pq Sq \e0 .
131 .It positive
132 Number of bytes for the valid multibyte character pointed to by
133 .Fa s .
134 There are no cases that the value returned is greater than
135 the value of the
136 .Dv MB_CUR_MAX
137 macro.
138 .It -1
139 .Fa s
140 points to an invalid or an incomplete multibyte character.
141 The
142 .Fn mbtowc
143 also sets
144 .Va errno
145 to indicate the error.
146 .El
147 .Pp
148 When
149 .Fa s
150 is equal to
151 .Dv NULL ,
152 .Fn mbtowc
153 returns:
154 .Bl -tag -width 0123456789
155 .It 0
156 The current encoding is state-independent.
157 .It non-zero
158 The current encoding is state-dependent.
159 .El
160 .\" ----------------------------------------------------------------------
161 .Sh ERRORS
162 .Fn mbtowc
163 may cause an error in the following case:
164 .Bl -tag -width Er
165 .It Bq Er EILSEQ
166 .Fa s
167 points to an invalid or incomplete multibyte character.
168 .El
169 .\" ----------------------------------------------------------------------
170 .Sh SEE ALSO
171 .Xr mblen 3 ,
172 .Xr mbrtowc 3 ,
173 .Xr setlocale 3
174 .\" ----------------------------------------------------------------------
175 .Sh STANDARDS
176 The
177 .Fn mbtowc
178 function conforms to
179 .St -ansiC .
180 The restrict qualifier is added at
181 .St -isoC-99 .