]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | .\" Copyright (c) 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Paul Borman at Krystal Technologies. | |
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 | .\" 3. All advertising materials mentioning features or use of this software | |
16 | .\" must display the following acknowledgement: | |
17 | .\" This product includes software developed by the University of | |
18 | .\" California, Berkeley and its contributors. | |
19 | .\" 4. Neither the name of the University nor the names of its contributors | |
20 | .\" may be used to endorse or promote products derived from this software | |
21 | .\" without specific prior written permission. | |
22 | .\" | |
23 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
24 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
27 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
28 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
29 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
31 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
33 | .\" SUCH DAMAGE. | |
34 | .\" | |
35 | .\" @(#)rune.3 8.2 (Berkeley) 12/11/93 | |
9385eb3d | 36 | .\" $FreeBSD: src/lib/libc/locale/rune.3,v 1.22 2002/12/19 09:40:22 ru Exp $ |
5b2abdfb | 37 | .\" |
9385eb3d | 38 | .Dd October 6, 2002 |
5b2abdfb A |
39 | .Dt RUNE 3 |
40 | .Os | |
41 | .Sh NAME | |
42 | .Nm setrunelocale , | |
43 | .Nm setinvalidrune , | |
44 | .Nm sgetrune , | |
45 | .Nm sputrune , | |
46 | .Nm fgetrune , | |
47 | .Nm fungetrune , | |
48 | .Nm fputrune | |
49 | .Nd rune support for C | |
50 | .Sh LIBRARY | |
51 | .Lb libc | |
52 | .Sh SYNOPSIS | |
53 | .In rune.h | |
54 | .In errno.h | |
55 | .Ft int | |
56 | .Fn setrunelocale "char *locale" | |
57 | .Ft void | |
58 | .Fn setinvalidrune "rune_t rune" | |
59 | .Ft rune_t | |
60 | .Fn sgetrune "const char *string" "size_t n" "char const **result" | |
61 | .Ft int | |
62 | .Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result" | |
63 | .Pp | |
64 | .In stdio.h | |
65 | .Ft long | |
66 | .Fn fgetrune "FILE *stream" | |
67 | .Ft int | |
68 | .Fn fungetrune "rune_t rune" "FILE *stream" | |
69 | .Ft int | |
70 | .Fn fputrune "rune_t rune" "FILE *stream" | |
71 | .Sh DESCRIPTION | |
9385eb3d A |
72 | .Bf Em |
73 | The | |
74 | .Bx 4.4 | |
75 | .Dq rune | |
76 | functions have been deprecated in favour of the | |
77 | .Tn ISO | |
78 | C99 extended multibyte and wide character facilities | |
79 | and should not be used in new applications. | |
80 | .Ef | |
81 | Consider using | |
82 | .Xr setlocale 3 , | |
83 | .Xr mbrtowc 3 , | |
84 | .Xr wcrtomb 3 , | |
85 | .Xr fgetwc 3 , | |
86 | .Xr ungetwc 3 , | |
87 | and | |
88 | .Xr fputwc 3 | |
89 | instead. | |
90 | .Pp | |
5b2abdfb A |
91 | The |
92 | .Fn setrunelocale | |
93 | controls the type of encoding used to represent runes as multibyte strings | |
94 | as well as the properties of the runes as defined in | |
95 | .Aq Pa ctype.h . | |
96 | The | |
97 | .Fa locale | |
98 | argument indicates which locale to load. | |
99 | If the locale is successfully loaded, | |
100 | .Dv 0 | |
101 | is returned, otherwise an errno value is returned to indicate the | |
102 | type of error. | |
103 | .Pp | |
104 | The | |
105 | .Fn setinvalidrune | |
106 | function sets the value of the global value | |
107 | .Dv _INVALID_RUNE | |
108 | to be | |
109 | .Fa rune . | |
110 | .Pp | |
111 | The | |
112 | .Fn sgetrune | |
113 | function tries to read a single multibyte character from | |
114 | .Fa string , | |
115 | which is at most | |
116 | .Fa n | |
117 | bytes long. | |
118 | If | |
119 | .Fn sgetrune | |
120 | is successful, the rune is returned. | |
121 | If | |
122 | .Fa result | |
123 | is not | |
124 | .Dv NULL , | |
125 | .Fa *result | |
126 | will point to the first byte which was not converted in | |
127 | .Fa string . | |
128 | If the first | |
129 | .Fa n | |
130 | bytes of | |
131 | .Fa string | |
132 | do not describe a full multibyte character, | |
133 | .Dv _INVALID_RUNE | |
134 | is returned and | |
135 | .Fa *result | |
136 | will point to | |
137 | .Fa string . | |
138 | If there is an encoding error at the start of | |
139 | .Fa string , | |
140 | .Dv _INVALID_RUNE | |
141 | is returned and | |
142 | .Fa *result | |
143 | will point to the second character of | |
144 | .Fa string . | |
145 | .Pp | |
146 | the | |
147 | .Fn sputrune | |
148 | function tries to encode | |
149 | .Fa rune | |
150 | as a multibyte string and store it at | |
151 | .Fa string , | |
152 | but no more than | |
153 | .Fa n | |
154 | bytes will be stored. | |
155 | If | |
156 | .Fa result | |
157 | is not | |
158 | .Dv NULL , | |
159 | .Fa *result | |
160 | will be set to point to the first byte in string following the new | |
161 | multibyte character. | |
162 | If | |
163 | .Fa string | |
164 | is | |
165 | .Dv NULL , | |
166 | .Fa *result | |
167 | will point to | |
168 | .Dv "(char *)0 +" | |
169 | .Fa x , | |
170 | where | |
171 | .Fa x | |
172 | is the number of bytes that would be needed to store the multibyte value. | |
173 | If the multibyte character would consist of more than | |
174 | .Fa n | |
175 | bytes and | |
176 | .Fa result | |
177 | is not | |
178 | .Dv NULL , | |
179 | .Fa *result | |
180 | will be set to | |
181 | .Dv NULL . | |
182 | In all cases, | |
183 | .Fn sputrune | |
184 | will return the number of bytes which would be needed to store | |
185 | .Fa rune | |
186 | as a multibyte character. | |
187 | .Pp | |
188 | The | |
189 | .Fn fgetrune | |
190 | function operates the same as | |
191 | .Fn sgetrune | |
192 | with the exception that it attempts to read enough bytes from | |
193 | .Fa stream | |
194 | to decode a single rune. It returns either | |
195 | .Dv EOF | |
196 | on end of file, | |
197 | .Dv _INVALID_RUNE | |
198 | on an encoding error, or the rune decoded if all went well. | |
199 | .Pp | |
200 | The | |
201 | .Fn fungetrune | |
202 | function pushes the multibyte encoding, as provided by | |
203 | .Fn sputrune , | |
204 | of | |
205 | .Fa rune | |
206 | onto | |
207 | .Fa stream | |
208 | such that the next | |
209 | .Fn fgetrune | |
210 | call will return | |
211 | .Fa rune . | |
212 | It returns | |
213 | .Dv EOF | |
214 | if it fails and | |
215 | .Dv 0 | |
216 | on success. | |
217 | .Pp | |
218 | The | |
219 | .Fn fputrune | |
220 | function writes the multibyte encoding of | |
221 | .Fa rune , | |
222 | as provided by | |
223 | .Fn sputrune , | |
224 | onto | |
225 | .Fa stream . | |
226 | It returns | |
227 | .Dv EOF | |
228 | on failure and | |
229 | .Dv 0 | |
230 | on success. | |
231 | .Sh RETURN VALUES | |
232 | The | |
233 | .Fn setrunelocale | |
234 | function returns one of the following values: | |
235 | .Bl -tag -width Er | |
236 | .It Er 0 | |
9385eb3d | 237 | The |
5b2abdfb | 238 | .Fn setrunelocale |
9385eb3d | 239 | function |
5b2abdfb | 240 | was successful. |
9385eb3d A |
241 | .It Bq Er EINVAL |
242 | The | |
5b2abdfb | 243 | .Fa locale |
9385eb3d | 244 | name was incorrect. |
5b2abdfb A |
245 | .It Bq Er ENOENT |
246 | The locale could not be found. | |
247 | .It Bq Er EFTYPE | |
248 | The file found was not a valid file. | |
5b2abdfb A |
249 | .El |
250 | .Pp | |
251 | The | |
252 | .Fn sgetrune | |
253 | function either returns the rune read or | |
254 | .Dv _INVALID_RUNE . | |
255 | The | |
256 | .Fn sputrune | |
257 | function returns the number of bytes needed to store | |
258 | .Fa rune | |
259 | as a multibyte string. | |
260 | .Sh FILES | |
261 | .Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact | |
262 | .It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE | |
263 | .It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE | |
264 | binary LC_CTYPE file for the locale | |
265 | .Em locale . | |
266 | .El | |
267 | .Sh SEE ALSO | |
268 | .Xr mbrune 3 , | |
269 | .Xr setlocale 3 , | |
270 | .Xr euc 4 , | |
9385eb3d A |
271 | .Xr utf2 4 , |
272 | .Xr utf8 5 | |
5b2abdfb A |
273 | .Sh HISTORY |
274 | These functions first appeared in | |
275 | .Bx 4.4 . | |
276 | .Pp | |
277 | The | |
278 | .Fn setrunelocale | |
279 | function and the other non-ANSI rune functions were inspired by | |
9385eb3d | 280 | .Sy "Plan 9 from Bell Labs" . |
5b2abdfb A |
281 | .\"They were conceived at the San Diego 1993 Summer USENIX conference by |
282 | .\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume | |
283 | .\"of Bell Labs. |