1 /*
2 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include "lint.h"
35 #include "file64.h"
36 #include <errno.h>
37 #include <limits.h>
38 #include <string.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <wchar.h>
43 #include "runetype.h"
44 #include "ldpart.h"
45 #include "mblocal.h"
46 #include "setlocale.h"
47 #include "_ctype.h"
48 #include "../i18n/_locale.h"
49
50 extern _RuneLocale *_Read_RuneMagi(FILE *);
51 extern unsigned char __ctype_C[];
52
53 static int __setrunelocale(const char *);
54
55 static int
56 __setrunelocale(const char *encoding)
57 {
58 FILE *fp;
59 char name[PATH_MAX];
60 _RuneLocale *rl;
61 int saverr, ret;
62 size_t (*old__mbrtowc)(wchar_t *_RESTRICT_KYWD,
63 const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
64 size_t (*old__wcrtomb)(char *_RESTRICT_KYWD, wchar_t,
65 mbstate_t *_RESTRICT_KYWD);
66 int (*old__mbsinit)(const mbstate_t *);
67 size_t (*old__mbsnrtowcs)(wchar_t *_RESTRICT_KYWD,
68 const char **_RESTRICT_KYWD, size_t, size_t,
69 mbstate_t *_RESTRICT_KYWD);
233 __mbsnrtowcs = old__mbsnrtowcs;
234 __wcrtomb = old__wcrtomb;
235 __wcsnrtombs = old__wcsnrtombs;
236 free(rl);
237 }
238
239 return (ret);
240 }
241
242 int
243 __wrap_setrunelocale(const char *locale)
244 {
245 int ret = __setrunelocale(locale);
246
247 if (ret != 0) {
248 errno = ret;
249 return (_LDP_ERROR);
250 }
251 return (_LDP_LOADED);
252 }
|
1 /*
2 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *
9 * Copyright (c) 2011 The FreeBSD Foundation
10 * All rights reserved.
11 * Portions of this software were developed by David Chisnall
12 * under sponsorship from the FreeBSD Foundation.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
39 #include "lint.h"
40 #include "file64.h"
41 #include <errno.h>
42 #include <limits.h>
43 #include <string.h>
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <unistd.h>
47 #include <wchar.h>
48 #include "runetype.h"
49 #include "ldpart.h"
50 #include "mblocal.h"
51 #include "setlocale.h"
52 #include "_ctype.h"
53 #include "../i18n/_locale.h"
54
55 /*
56 * A cached version of the runes for this thread. Used by ctype.h
57 */
58 __thread const _RuneLocale *_ThreadRuneLocale;
59
60 extern _RuneLocale *_Read_RuneMagi(FILE *);
61 extern unsigned char __ctype_C[];
62
63 static int __setrunelocale(const char *);
64
65 static int
66 __setrunelocale(const char *encoding)
67 {
68 FILE *fp;
69 char name[PATH_MAX];
70 _RuneLocale *rl;
71 int saverr, ret;
72 size_t (*old__mbrtowc)(wchar_t *_RESTRICT_KYWD,
73 const char *_RESTRICT_KYWD, size_t, mbstate_t *_RESTRICT_KYWD);
74 size_t (*old__wcrtomb)(char *_RESTRICT_KYWD, wchar_t,
75 mbstate_t *_RESTRICT_KYWD);
76 int (*old__mbsinit)(const mbstate_t *);
77 size_t (*old__mbsnrtowcs)(wchar_t *_RESTRICT_KYWD,
78 const char **_RESTRICT_KYWD, size_t, size_t,
79 mbstate_t *_RESTRICT_KYWD);
243 __mbsnrtowcs = old__mbsnrtowcs;
244 __wcrtomb = old__wcrtomb;
245 __wcsnrtombs = old__wcsnrtombs;
246 free(rl);
247 }
248
249 return (ret);
250 }
251
252 int
253 __wrap_setrunelocale(const char *locale)
254 {
255 int ret = __setrunelocale(locale);
256
257 if (ret != 0) {
258 errno = ret;
259 return (_LDP_ERROR);
260 }
261 return (_LDP_LOADED);
262 }
263
264 void
265 __set_thread_rune_locale(locale_t loc)
266 {
267
268 if (loc == NULL) {
269 _ThreadRuneLocale = &_DefaultRuneLocale;
270 } else {
271 _ThreadRuneLocale = XLOCALE_CTYPE(loc)->runes;
272 }
273 }
274
275 void *
276 __ctype_load(const char *locale, locale_t unused)
277 {
278 struct xlocale_ctype *l;
279
280 l = calloc(sizeof(struct xlocale_ctype), 1);
281 /* XXX */
282
283 return (l);
284 }
|