Blame locale/lc-ctype.c

Packit Service 82fcde
/* Define current locale data for LC_CTYPE category.
Packit Service 82fcde
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include "localeinfo.h"
Packit Service 82fcde
#include <ctype.h>
Packit Service 82fcde
#include <endian.h>
Packit Service 82fcde
#include <stdint.h>
Packit Service 82fcde
Packit Service 82fcde
_NL_CURRENT_DEFINE (LC_CTYPE);
Packit Service 82fcde
Packit Service 82fcde
/* We are called after loading LC_CTYPE data to load it into
Packit Service 82fcde
   the variables used by the ctype.h macros.  */
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
void
Packit Service 82fcde
_nl_postload_ctype (void)
Packit Service 82fcde
{
Packit Service 82fcde
#define current(type,x,offset) \
Packit Service 82fcde
  ((const type *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_##x) + offset)
Packit Service 82fcde
Packit Service 82fcde
  const union locale_data_value *const ctypes
Packit Service 82fcde
    = _nl_global_locale.__locales[LC_CTYPE]->values;
Packit Service 82fcde
Packit Service 82fcde
/* These thread-local variables are defined in ctype-info.c.
Packit Service 82fcde
   The declarations here must match those in localeinfo.h.
Packit Service 82fcde
Packit Service 82fcde
   These point into arrays of 384, so they can be indexed by any `unsigned
Packit Service 82fcde
   char' value [0,255]; by EOF (-1); or by any `signed char' value
Packit Service 82fcde
   [-128,-1).  ISO C requires that the ctype functions work for `unsigned
Packit Service 82fcde
   char' values and for EOF; we also support negative `signed char' values
Packit Service 82fcde
   for broken old programs.  The case conversion arrays are of `int's
Packit Service 82fcde
   rather than `unsigned char's because tolower (EOF) must be EOF, which
Packit Service 82fcde
   doesn't fit into an `unsigned char'.  But today more important is that
Packit Service 82fcde
   the arrays are also used for multi-byte character sets.
Packit Service 82fcde
Packit Service 82fcde
   First we update the special members of _nl_global_locale as newlocale
Packit Service 82fcde
   would.  This is necessary for uselocale (LC_GLOBAL_LOCALE) to find these
Packit Service 82fcde
   values properly.  */
Packit Service 82fcde
Packit Service 82fcde
  _nl_global_locale.__ctype_b = (const unsigned short int *)
Packit Service 82fcde
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)].string + 128;
Packit Service 82fcde
  _nl_global_locale.__ctype_tolower = (const int *)
Packit Service 82fcde
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string + 128;
Packit Service 82fcde
  _nl_global_locale.__ctype_toupper = (const int *)
Packit Service 82fcde
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string + 128;
Packit Service 82fcde
Packit Service 82fcde
  /* Next we must set the thread-local caches if and only if this thread is
Packit Service 82fcde
     in fact using the global locale.  */
Packit Service 82fcde
  if (_NL_CURRENT_LOCALE == &_nl_global_locale)
Packit Service 82fcde
    {
Packit Service 82fcde
      __libc_tsd_set (const uint16_t *, CTYPE_B,
Packit Service 82fcde
		      (void *) _nl_global_locale.__ctype_b);
Packit Service 82fcde
      __libc_tsd_set (const int32_t *, CTYPE_TOUPPER,
Packit Service 82fcde
		      (void *) _nl_global_locale.__ctype_toupper);
Packit Service 82fcde
      __libc_tsd_set (const int32_t *, CTYPE_TOLOWER,
Packit Service 82fcde
		      (void *) _nl_global_locale.__ctype_tolower);
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
#include <shlib-compat.h>
Packit Service 82fcde
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3)
Packit Service 82fcde
  /* We must use the exported names to access these so we are sure to
Packit Service 82fcde
     be accessing the main executable's copy if it has COPY relocs.  */
Packit Service 82fcde
Packit Service 82fcde
  extern const unsigned short int *__ctype_b; /* Characteristics.  */
Packit Service 82fcde
  extern const __int32_t *__ctype_tolower; /* Case conversions.  */
Packit Service 82fcde
  extern const __int32_t *__ctype_toupper; /* Case conversions.  */
Packit Service 82fcde
Packit Service 82fcde
  extern const uint32_t *__ctype32_b;
Packit Service 82fcde
  extern const uint32_t *__ctype32_toupper;
Packit Service 82fcde
  extern const uint32_t *__ctype32_tolower;
Packit Service 82fcde
Packit Service 82fcde
  /* We need the .symver declarations these macros generate so that
Packit Service 82fcde
     our references are explicitly bound to the versioned symbol names
Packit Service 82fcde
     rather than the unadorned names that are not exported.  When the
Packit Service 82fcde
     linker sees these bound to local symbols (as the unexported names are)
Packit Service 82fcde
     then it doesn't generate a proper relocation to the global symbols.
Packit Service 82fcde
     We need those relocations so that a versioned definition with a COPY
Packit Service 82fcde
     reloc in an executable will override the libc.so definition.  */
Packit Service 82fcde
Packit Service 82fcde
compat_symbol (libc, __ctype_b, __ctype_b, GLIBC_2_0);
Packit Service 82fcde
compat_symbol (libc, __ctype_tolower, __ctype_tolower, GLIBC_2_0);
Packit Service 82fcde
compat_symbol (libc, __ctype_toupper, __ctype_toupper, GLIBC_2_0);
Packit Service 82fcde
compat_symbol (libc, __ctype32_b, __ctype32_b, GLIBC_2_0);
Packit Service 82fcde
compat_symbol (libc, __ctype32_tolower, __ctype32_tolower, GLIBC_2_2);
Packit Service 82fcde
compat_symbol (libc, __ctype32_toupper, __ctype32_toupper, GLIBC_2_2);
Packit Service 82fcde
Packit Service 82fcde
  __ctype_b = current (uint16_t, CLASS, 128);
Packit Service 82fcde
  __ctype_toupper = current (int32_t, TOUPPER, 128);
Packit Service 82fcde
  __ctype_tolower = current (int32_t, TOLOWER, 128);
Packit Service 82fcde
  __ctype32_b = current (uint32_t, CLASS32, 0);
Packit Service 82fcde
  __ctype32_toupper = current (uint32_t, TOUPPER32, 0);
Packit Service 82fcde
  __ctype32_tolower = current (uint32_t, TOLOWER32, 0);
Packit Service 82fcde
#endif
Packit Service 82fcde
}