Update.
[glibc.git] / locale / lc-ctype.c
blobeb108416d27a9a15415e5584d1d53b00d43ae41c
1 /* Define current locale data for LC_CTYPE category.
2 Copyright (C) 1995-1999, 2000, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include "localeinfo.h"
21 #include <ctype.h>
22 #include <endian.h>
23 #include <stdint.h>
25 _NL_CURRENT_DEFINE (LC_CTYPE);
27 /* We are called after loading LC_CTYPE data to load it into
28 the variables used by the ctype.h macros. */
32 void
33 _nl_postload_ctype (void)
35 #define current(type,x,offset) \
36 ((const type *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_##x) + offset)
38 /* These are defined in ctype-info.c.
39 The declarations here must match those in localeinfo.h.
41 These point into arrays of 384, so they can be indexed by any `unsigned
42 char' value [0,255]; by EOF (-1); or by any `signed char' value
43 [-128,-1). ISO C requires that the ctype functions work for `unsigned
44 char' values and for EOF; we also support negative `signed char' values
45 for broken old programs. The case conversion arrays are of `int's
46 rather than `unsigned char's because tolower (EOF) must be EOF, which
47 doesn't fit into an `unsigned char'. But today more important is that
48 the arrays are also used for multi-byte character sets. */
50 if (_NL_CURRENT_LOCALE == &_nl_global_locale)
52 __libc_tsd_set (CTYPE_B, (void *) current (uint16_t, CLASS, 128));
53 __libc_tsd_set (CTYPE_TOUPPER, (void *) current (int32_t, TOUPPER, 128));
54 __libc_tsd_set (CTYPE_TOLOWER, (void *) current (int32_t, TOLOWER, 128));
57 #include <shlib-compat.h>
58 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
59 /* We must use the exported names to access these so we are sure to
60 be accessing the main executable's copy if it has COPY relocs. */
62 extern __const unsigned short int *__ctype_b; /* Characteristics. */
63 extern __const __int32_t *__ctype_tolower; /* Case conversions. */
64 extern __const __int32_t *__ctype_toupper; /* Case conversions. */
66 extern const uint32_t *__ctype32_b;
67 extern const uint32_t *__ctype32_toupper;
68 extern const uint32_t *__ctype32_tolower;
70 /* We need the .symver declarations these macros generate so that
71 our references are explicitly bound to the versioned symbol names
72 rather than the unadorned names that are not exported. When the
73 linker sees these bound to local symbols (as the unexported names are)
74 then it doesn't generate a proper relocation to the global symbols.
75 We need those relocations so that a versioned definition with a COPY
76 reloc in an executable will override the libc.so definition. */
78 compat_symbol (libc, __ctype_b, __ctype_b, GLIBC_2_0);
79 compat_symbol (libc, __ctype_tolower, __ctype_tolower, GLIBC_2_0);
80 compat_symbol (libc, __ctype_toupper, __ctype_toupper, GLIBC_2_0);
81 compat_symbol (libc, __ctype32_b, __ctype32_b, GLIBC_2_0);
82 compat_symbol (libc, __ctype32_tolower, __ctype32_tolower, GLIBC_2_2);
83 compat_symbol (libc, __ctype32_toupper, __ctype32_toupper, GLIBC_2_2);
85 __ctype_b = current (uint16_t, CLASS, 128);
86 __ctype_toupper = current (uint32_t, TOUPPER, 128);
87 __ctype_tolower = current (uint32_t, TOLOWER, 128);
88 __ctype32_b = current (uint32_t, CLASS32, 0);
89 __ctype32_toupper = current (uint32_t, TOUPPER32, 0);
90 __ctype32_tolower = current (uint32_t, TOLOWER32, 0);
91 #endif