2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that the following conditions
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.
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
24 #include "setlocale.h"
26 #define LCCTYPE_SIZE (sizeof(struct lc_ctype_T) / sizeof(char *))
28 static char numone
[] = { '\1', '\0'};
30 const struct lc_ctype_T _C_ctype_locale
= {
31 "ASCII", /* codeset */
32 numone
/* mb_cur_max */
33 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
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" }
43 static char numsix
[] = { '\6', '\0'};
45 const struct lc_ctype_T _C_utf8_ctype_locale
= {
46 "UTF-8", /* codeset */
47 numsix
/* mb_cur_max */
48 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
50 { "0", "1", "2", "3", "4", /* outdigits */
51 "5", "6", "7", "8", "9" },
52 { L
"0", L
"1", L
"2", L
"3", L
"4", /* woutdigits */
53 L
"5", L
"6", L
"7", L
"8", L
"9" }
58 /* NULL locale indicates global locale (called from setlocale) */
60 __ctype_load_locale (struct __locale_t
*locale
, const char *name
,
61 void *f_wctomb
, const char *charset
, int mb_cur_max
)
68 extern int __set_lc_ctype_from_win (const char *, const struct lc_ctype_T
*,
69 struct lc_ctype_T
*, char **, void *,
71 ret
= __set_lc_ctype_from_win (name
, &_C_ctype_locale
, &ct
, &bufp
,
72 f_wctomb
, charset
, mb_cur_max
);
73 /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
76 struct lc_ctype_T
*ctp
= NULL
;
80 ctp
= (struct lc_ctype_T
*) calloc (1, sizeof *ctp
);
88 struct __lc_cats tmp
= locale
->lc_cat
[LC_CTYPE
];
89 locale
->lc_cat
[LC_CTYPE
].ptr
= ret
== 0 ? &_C_ctype_locale
: ctp
;
90 locale
->lc_cat
[LC_CTYPE
].buf
= bufp
;
91 /* If buf is not NULL, both pointers have been alloc'ed */
94 free ((void *) tmp
.ptr
);