Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / locale / lctype.c
bloba07ab68124d2ca5c7884f0bb9e3aa34d1ad46789
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.
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.
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" }
39 #endif
42 #ifdef __CYGWIN__
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" }
54 #endif
56 #endif
58 /* NULL locale indicates global locale (called from setlocale) */
59 int
60 __ctype_load_locale (struct __locale_t *locale, const char *name,
61 void *f_wctomb, const char *charset, int mb_cur_max)
63 int ret;
64 struct lc_ctype_T ct;
65 char *bufp = NULL;
67 #ifdef __CYGWIN__
68 extern int __set_lc_ctype_from_win (const char *, const struct lc_ctype_T *,
69 struct lc_ctype_T *, char **, void *,
70 const char *, int);
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 */
74 if (ret >= 0)
76 struct lc_ctype_T *ctp = NULL;
78 if (ret > 0)
80 ctp = (struct lc_ctype_T *) calloc (1, sizeof *ctp);
81 if (!ctp)
83 free (bufp);
84 return -1;
86 *ctp = ct;
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 */
92 if (tmp.buf)
94 free ((void *) tmp.ptr);
95 free (tmp.buf);
97 ret = 0;
99 #else
100 /* TODO */
101 #endif
102 return ret;