1 | /* |
---|
2 | * Redistribution and use in source and binary forms, with or without |
---|
3 | * modification, are permitted provided that the following conditions |
---|
4 | * are met: |
---|
5 | * 1. Redistributions of source code must retain the above copyright |
---|
6 | * notice, this list of conditions and the following disclaimer. |
---|
7 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
8 | * notice, this list of conditions and the following disclaimer in the |
---|
9 | * documentation and/or other materials provided with the distribution. |
---|
10 | * |
---|
11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
12 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
13 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
14 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
15 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
16 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
17 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
18 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
19 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
20 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
21 | * SUCH DAMAGE. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "setlocale.h" |
---|
25 | |
---|
26 | #define LCCTYPE_SIZE (sizeof(struct lc_ctype_T) / sizeof(char *)) |
---|
27 | |
---|
28 | static char numone[] = { '\1', '\0'}; |
---|
29 | |
---|
30 | const struct lc_ctype_T _C_ctype_locale = { |
---|
31 | "ASCII", /* codeset */ |
---|
32 | numone /* mb_cur_max */ |
---|
33 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
34 | , |
---|
35 | { "0", "1", "2", "3", "4", /* outdigits */ |
---|
36 | "5", "6", "7", "8", "9" }, |
---|
37 | { L"0", L"1", L"2", L"3", L"4", /* woutdigits */ |
---|
38 | L"5", L"6", L"7", L"8", L"9" } |
---|
39 | #endif |
---|
40 | }; |
---|
41 | |
---|
42 | /* NULL locale indicates global locale (called from setlocale) */ |
---|
43 | int |
---|
44 | __ctype_load_locale (struct __locale_t *locale, const char *name, |
---|
45 | void *f_wctomb, const char *charset, int mb_cur_max) |
---|
46 | { |
---|
47 | int ret; |
---|
48 | struct lc_ctype_T ct; |
---|
49 | char *bufp = NULL; |
---|
50 | |
---|
51 | #ifdef __CYGWIN__ |
---|
52 | extern int __set_lc_ctype_from_win (const char *, const struct lc_ctype_T *, |
---|
53 | struct lc_ctype_T *, char **, void *, |
---|
54 | const char *, int); |
---|
55 | ret = __set_lc_ctype_from_win (name, &_C_ctype_locale, &ct, &bufp, |
---|
56 | f_wctomb, charset, mb_cur_max); |
---|
57 | /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ |
---|
58 | if (ret >= 0) |
---|
59 | { |
---|
60 | struct lc_ctype_T *ctp = NULL; |
---|
61 | |
---|
62 | if (ret > 0) |
---|
63 | { |
---|
64 | ctp = (struct lc_ctype_T *) calloc (1, sizeof *ctp); |
---|
65 | if (!ctp) |
---|
66 | { |
---|
67 | free (bufp); |
---|
68 | return -1; |
---|
69 | } |
---|
70 | *ctp = ct; |
---|
71 | } |
---|
72 | struct __lc_cats tmp = locale->lc_cat[LC_CTYPE]; |
---|
73 | locale->lc_cat[LC_CTYPE].ptr = ret == 0 ? &_C_ctype_locale : ctp; |
---|
74 | locale->lc_cat[LC_CTYPE].buf = bufp; |
---|
75 | /* If buf is not NULL, both pointers have been alloc'ed */ |
---|
76 | if (tmp.buf) |
---|
77 | { |
---|
78 | free ((void *) tmp.ptr); |
---|
79 | free (tmp.buf); |
---|
80 | } |
---|
81 | ret = 0; |
---|
82 | } |
---|
83 | #else |
---|
84 | /* TODO */ |
---|
85 | #endif |
---|
86 | return ret; |
---|
87 | } |
---|