Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / ctype / ctype_.c
blob32ce4f3187dc528c3103d6d884708d7f364a6698
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
30 #if defined(LIBC_SCCS) && !defined(lint)
31 static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90";
32 #endif /* LIBC_SCCS and not lint */
34 #include "ctype_.h"
35 #include "../locale/setlocale.h"
37 #define _CTYPE_DATA_0_127 \
38 _C, _C, _C, _C, _C, _C, _C, _C, \
39 _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \
40 _C, _C, _C, _C, _C, _C, _C, _C, \
41 _C, _C, _C, _C, _C, _C, _C, _C, \
42 _S|_B, _P, _P, _P, _P, _P, _P, _P, \
43 _P, _P, _P, _P, _P, _P, _P, _P, \
44 _N, _N, _N, _N, _N, _N, _N, _N, \
45 _N, _N, _P, _P, _P, _P, _P, _P, \
46 _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \
47 _U, _U, _U, _U, _U, _U, _U, _U, \
48 _U, _U, _U, _U, _U, _U, _U, _U, \
49 _U, _U, _U, _P, _P, _P, _P, _P, \
50 _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \
51 _L, _L, _L, _L, _L, _L, _L, _L, \
52 _L, _L, _L, _L, _L, _L, _L, _L, \
53 _L, _L, _L, _P, _P, _P, _P, _C
55 #define _CTYPE_DATA_128_255 \
56 0, 0, 0, 0, 0, 0, 0, 0, \
57 0, 0, 0, 0, 0, 0, 0, 0, \
58 0, 0, 0, 0, 0, 0, 0, 0, \
59 0, 0, 0, 0, 0, 0, 0, 0, \
60 0, 0, 0, 0, 0, 0, 0, 0, \
61 0, 0, 0, 0, 0, 0, 0, 0, \
62 0, 0, 0, 0, 0, 0, 0, 0, \
63 0, 0, 0, 0, 0, 0, 0, 0, \
64 0, 0, 0, 0, 0, 0, 0, 0, \
65 0, 0, 0, 0, 0, 0, 0, 0, \
66 0, 0, 0, 0, 0, 0, 0, 0, \
67 0, 0, 0, 0, 0, 0, 0, 0, \
68 0, 0, 0, 0, 0, 0, 0, 0, \
69 0, 0, 0, 0, 0, 0, 0, 0, \
70 0, 0, 0, 0, 0, 0, 0, 0, \
71 0, 0, 0, 0, 0, 0, 0, 0
73 #if defined(_MB_CAPABLE)
74 #if defined(_MB_EXTENDED_CHARSETS_ISO)
75 #include "ctype_iso.h"
76 #endif
77 #if defined(_MB_EXTENDED_CHARSETS_WINDOWS)
78 #include "ctype_cp.h"
79 #endif
80 #endif
82 #if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
83 /* No static const on Cygwin since it's referenced and potentially overwritten
84 for compatibility with older applications. */
85 #ifndef __CYGWIN__
86 const
87 #endif
88 char _ctype_b[128 + 256] = {
89 _CTYPE_DATA_128_255,
90 _CTYPE_DATA_0_127,
91 _CTYPE_DATA_128_255
94 # ifdef __CYGWIN__
95 /* For backward compatibility */
96 char __EXPORT *__ctype_ptr__ = DEFAULT_CTYPE_PTR;
98 # ifdef __x86_64__
99 __asm__ (" \n\
100 .data \n\
101 .globl _ctype_ \n\
102 .set _ctype_,_ctype_b+127 \n\
103 .text \n\
105 # else
106 __asm__ (" \n\
107 .data \n\
108 .globl __ctype_ \n\
109 .set __ctype_,__ctype_b+127 \n\
110 .text \n\
112 # endif
113 # else /* !__CYGWIN__ */
115 const char _ctype_[1 + 256] = {
117 _CTYPE_DATA_0_127,
118 _CTYPE_DATA_128_255
120 # endif /* !__CYGWIN__ */
122 #else /* !ALLOW_NEGATIVE_CTYPE_INDEX */
124 const char _ctype_[1 + 256] = {
126 _CTYPE_DATA_0_127,
127 _CTYPE_DATA_128_255
130 #endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */
132 #if defined(_MB_CAPABLE)
133 /* Cygwin has its own implementation which additionally maintains backward
134 compatibility with applications built under older Cygwin releases. */
135 #ifndef __CYGWIN__
136 void
137 __set_ctype (struct __locale_t *loc, const char *charset)
139 #if defined(_MB_EXTENDED_CHARSETS_ISO) || defined(_MB_EXTENDED_CHARSETS_WINDOWS)
140 int idx;
141 #endif
142 char *ctype_ptr = NULL;
144 switch (*charset)
146 #if defined(_MB_EXTENDED_CHARSETS_ISO)
147 case 'I':
148 idx = __iso_8859_index (charset + 9);
149 /* The ctype table has a leading ISO-8859-1 element so we have to add
150 1 to the index returned by __iso_8859_index. If __iso_8859_index
151 returns < 0, it's ISO-8859-1. */
152 if (idx < 0)
153 idx = 0;
154 else
155 ++idx;
156 ctype_ptr = __ctype_iso[idx];
157 break;
158 #endif
159 #if defined(_MB_EXTENDED_CHARSETS_WINDOWS)
160 case 'C':
161 idx = __cp_index (charset + 2);
162 if (idx < 0)
163 break;
164 ctype_ptr = __ctype_cp[idx];
165 break;
166 #endif
167 default:
168 break;
170 if (!ctype_ptr)
172 # if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
173 ctype_ptr = _ctype_b;
174 # else
175 ctype_ptr = _ctype_;
176 # endif
178 # if defined(ALLOW_NEGATIVE_CTYPE_INDEX)
179 loc->ctype_ptr = ctype_ptr + 127;
180 # else
181 loc->ctype_ptr = ctype_ptr;
182 # endif
184 #endif /* !__CYGWIN__ */
185 #endif /* _MB_CAPABLE */