Blame locale/localeinfo.h

Packit 6c4009
/* Declarations for internal libc locale interfaces
Packit 6c4009
   Copyright (C) 1995-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _LOCALEINFO_H
Packit 6c4009
#define _LOCALEINFO_H 1
Packit 6c4009
Packit 6c4009
#include <stddef.h>
Packit 6c4009
#include <langinfo.h>
Packit 6c4009
#include <limits.h>
Packit 6c4009
#include <locale.h>
Packit 6c4009
#include <time.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <sys/types.h>
Packit 6c4009
Packit 6c4009
#include <intl/loadinfo.h>	/* For loaded_l10nfile definition.  */
Packit 6c4009
Packit 6c4009
/* Magic number at the beginning of a locale data file for CATEGORY.  */
Packit 6c4009
#define	LIMAGIC(category) \
Packit 6c4009
  (category == LC_COLLATE						\
Packit 6c4009
   ? ((unsigned int) (0x20051014 ^ (category)))				\
Packit 6c4009
   : category == LC_CTYPE						\
Packit 6c4009
   ? ((unsigned int) (0x20090720 ^ (category)))				\
Packit 6c4009
   : ((unsigned int) (0x20031115 ^ (category))))
Packit 6c4009
Packit 6c4009
/* Two special weight constants for the collation data.  */
Packit 6c4009
#define IGNORE_CHAR	2
Packit 6c4009
Packit 6c4009
/* We use a special value for the usage counter in `__locale_data' to
Packit 6c4009
   signal that this data must never be removed anymore.  */
Packit 6c4009
#define MAX_USAGE_COUNT (UINT_MAX - 1)
Packit 6c4009
#define UNDELETABLE	UINT_MAX
Packit 6c4009
Packit 6c4009
/* Structure describing locale data in core for a category.  */
Packit 6c4009
struct __locale_data
Packit 6c4009
{
Packit 6c4009
  const char *name;
Packit 6c4009
  const char *filedata;		/* Region mapping the file data.  */
Packit 6c4009
  off_t filesize;		/* Size of the file (and the region).  */
Packit 6c4009
  enum				/* Flavor of storage used for those.  */
Packit 6c4009
  {
Packit 6c4009
    ld_malloced,		/* Both are malloc'd.  */
Packit 6c4009
    ld_mapped,			/* name is malloc'd, filedata mmap'd */
Packit 6c4009
    ld_archive			/* Both point into mmap'd archive regions.  */
Packit 6c4009
  } alloc;
Packit 6c4009
Packit 6c4009
  /* This provides a slot for category-specific code to cache data computed
Packit 6c4009
     about this locale.  That code can set a cleanup function to deallocate
Packit 6c4009
     the data.  */
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
    void (*cleanup) (struct __locale_data *);
Packit 6c4009
    union
Packit 6c4009
    {
Packit 6c4009
      void *data;
Packit 6c4009
      struct lc_time_data *time;
Packit 6c4009
      const struct gconv_fcts *ctype;
Packit 6c4009
    };
Packit 6c4009
  } private;
Packit 6c4009
Packit 6c4009
  unsigned int usage_count;	/* Counter for users.  */
Packit 6c4009
Packit 6c4009
  int use_translit;		/* Nonzero if the mb*towv*() and wc*tomb()
Packit 6c4009
				   functions should use transliteration.  */
Packit 6c4009
Packit 6c4009
  unsigned int nstrings;	/* Number of strings below.  */
Packit 6c4009
  union locale_data_value
Packit 6c4009
  {
Packit 6c4009
    const uint32_t *wstr;
Packit 6c4009
    const char *string;
Packit 6c4009
    unsigned int word;		/* Note endian issues vs 64-bit pointers.  */
Packit 6c4009
  }
Packit 6c4009
  values __flexarr;	/* Items, usually pointers into `filedata'.  */
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* This alignment is used for 32-bit integers in locale files, both
Packit 6c4009
   those that are explicitly int32_t or uint32_t and those that are
Packit 6c4009
   wchar_t, regardless of the (possibly smaller) alignment required
Packit 6c4009
   for such integers on a particular host.  */
Packit 6c4009
#define LOCFILE_ALIGN		sizeof (int32_t)
Packit 6c4009
#define LOCFILE_ALIGN_MASK	(LOCFILE_ALIGN - 1)
Packit 6c4009
#define LOCFILE_ALIGN_UP(x)	(((x) + LOCFILE_ALIGN - 1)	\
Packit 6c4009
				 & ~LOCFILE_ALIGN_MASK)
Packit 6c4009
#define LOCFILE_ALIGNED_P(x)	(((x) & LOCFILE_ALIGN_MASK) == 0)
Packit 6c4009
Packit 6c4009
/* We know three kinds of collation sorting rules.  */
Packit 6c4009
enum coll_sort_rule
Packit 6c4009
{
Packit 6c4009
  illegal_0__,
Packit 6c4009
  sort_forward,
Packit 6c4009
  sort_backward,
Packit 6c4009
  illegal_3__,
Packit 6c4009
  sort_position,
Packit 6c4009
  sort_forward_position,
Packit 6c4009
  sort_backward_position,
Packit 6c4009
  sort_mask
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* We can map the types of the entries into a few categories.  */
Packit 6c4009
enum value_type
Packit 6c4009
{
Packit 6c4009
  none,
Packit 6c4009
  string,
Packit 6c4009
  stringarray,
Packit 6c4009
  byte,
Packit 6c4009
  bytearray,
Packit 6c4009
  word,
Packit 6c4009
  stringlist,
Packit 6c4009
  wordarray,
Packit 6c4009
  wstring,
Packit 6c4009
  wstringarray,
Packit 6c4009
  wstringlist
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Definitions for `era' information from LC_TIME.  */
Packit 6c4009
#define ERA_NAME_FORMAT_MEMBERS 4
Packit 6c4009
#define ERA_M_NAME   0
Packit 6c4009
#define ERA_M_FORMAT 1
Packit 6c4009
#define ERA_W_NAME   2
Packit 6c4009
#define ERA_W_FORMAT 3
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Structure to access `era' information from LC_TIME.  */
Packit 6c4009
struct era_entry
Packit 6c4009
{
Packit 6c4009
  uint32_t direction;		/* Contains '+' or '-'.  */
Packit 6c4009
  int32_t offset;
Packit 6c4009
  int32_t start_date[3];
Packit 6c4009
  int32_t stop_date[3];
Packit 6c4009
  const char *era_name;
Packit 6c4009
  const char *era_format;
Packit 6c4009
  const wchar_t *era_wname;
Packit 6c4009
  const wchar_t *era_wformat;
Packit 6c4009
  int absolute_direction;
Packit 6c4009
  /* absolute direction:
Packit 6c4009
     +1 indicates that year number is higher in the future. (like A.D.)
Packit 6c4009
     -1 indicates that year number is higher in the past. (like B.C.)  */
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
/* Structure caching computed data about information from LC_TIME.
Packit 6c4009
   The `private.time' member of `struct __locale_data' points to this.  */
Packit 6c4009
struct lc_time_data
Packit 6c4009
{
Packit 6c4009
  struct era_entry *eras;
Packit 6c4009
  size_t num_eras;
Packit 6c4009
  int era_initialized;
Packit 6c4009
Packit 6c4009
  const char **alt_digits;
Packit 6c4009
  const wchar_t **walt_digits;
Packit 6c4009
  int alt_digits_initialized;
Packit 6c4009
  int walt_digits_initialized;
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* LC_CTYPE specific:
Packit 6c4009
   Hardwired indices for standard wide character translation mappings.  */
Packit 6c4009
enum
Packit 6c4009
{
Packit 6c4009
  __TOW_toupper = 0,
Packit 6c4009
  __TOW_tolower = 1
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* LC_CTYPE specific:
Packit 6c4009
   Access a wide character class with a single character index.
Packit 6c4009
   _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
Packit 6c4009
   c must be an `unsigned char'.  desc must be a nonzero wctype_t.  */
Packit 6c4009
#define _ISCTYPE(c, desc) \
Packit 6c4009
  (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
Packit 6c4009
Packit 6c4009
/* Category name handling variables.  */
Packit 6c4009
#define CATNAMEMF(line) CATNAMEMF1 (line)
Packit 6c4009
#define CATNAMEMF1(line) str##line
Packit 6c4009
extern const union catnamestr_t
Packit 6c4009
{
Packit 6c4009
  struct
Packit 6c4009
  {
Packit 6c4009
#define DEFINE_CATEGORY(category, category_name, items, a) \
Packit 6c4009
    char CATNAMEMF (__LINE__)[sizeof (category_name)];
Packit 6c4009
#include "categories.def"
Packit 6c4009
#undef DEFINE_CATEGORY
Packit 6c4009
  };
Packit 6c4009
  char str[0];
Packit 6c4009
} _nl_category_names attribute_hidden;
Packit 6c4009
extern const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden;
Packit 6c4009
extern const uint8_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Name of the standard locales.  */
Packit 6c4009
extern const char _nl_C_name[] attribute_hidden;
Packit 6c4009
extern const char _nl_POSIX_name[] attribute_hidden;
Packit 6c4009
Packit 6c4009
/* The standard codeset.  */
Packit 6c4009
extern const char _nl_C_codeset[] attribute_hidden;
Packit 6c4009
Packit 6c4009
/* This is the internal locale_t object that holds the global locale
Packit 6c4009
   controlled by calls to setlocale.  A thread's TSD locale pointer
Packit 6c4009
   points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect.  */
Packit 6c4009
extern struct __locale_struct _nl_global_locale attribute_hidden;
Packit 6c4009
Packit 6c4009
/* This fetches the thread-local locale_t pointer, either one set with
Packit 6c4009
   uselocale or &_nl_global_locale.  */
Packit 6c4009
#define _NL_CURRENT_LOCALE	(__libc_tsd_get (locale_t, LOCALE))
Packit 6c4009
#include <libc-tsd.h>
Packit 6c4009
__libc_tsd_define (extern, locale_t, LOCALE)
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* For static linking it is desireable to avoid always linking in the code
Packit 6c4009
   and data for every category when we can tell at link time that they are
Packit 6c4009
   unused.  We can manage this playing some tricks with weak references.
Packit 6c4009
   But with thread-local locale settings, it becomes quite ungainly unless
Packit 6c4009
   we can use __thread variables.  So only in that case do we attempt this.  */
Packit 6c4009
#ifndef SHARED
Packit 6c4009
# include <tls.h>
Packit 6c4009
# define NL_CURRENT_INDIRECT	1
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#ifdef NL_CURRENT_INDIRECT
Packit 6c4009
Packit 6c4009
/* For each category declare the thread-local variable for the current
Packit 6c4009
   locale data.  This has an extra indirection so it points at the
Packit 6c4009
   __locales[CATEGORY] element in either _nl_global_locale or the current
Packit 6c4009
   locale object set by uselocale, which points at the actual data.  The
Packit 6c4009
   reason for having these variables is so that references to particular
Packit 6c4009
   categories will link in the lc-CATEGORY.c module to define this symbol,
Packit 6c4009
   and we arrange that linking that module is what brings in all the code
Packit 6c4009
   associated with this category.  */
Packit 6c4009
#define DEFINE_CATEGORY(category, category_name, items, a) \
Packit 6c4009
extern __thread struct __locale_data *const *_nl_current_##category \
Packit 6c4009
  attribute_hidden attribute_tls_model_ie;
Packit 6c4009
#include "categories.def"
Packit 6c4009
#undef	DEFINE_CATEGORY
Packit 6c4009
Packit 6c4009
/* Return a pointer to the current `struct __locale_data' for CATEGORY.  */
Packit 6c4009
#define _NL_CURRENT_DATA(category)	(*_nl_current_##category)
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's string for ITEM.  */
Packit 6c4009
#define _NL_CURRENT(category, item) \
Packit 6c4009
  ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string)
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's string for ITEM.  */
Packit 6c4009
#define _NL_CURRENT_WSTR(category, item) \
Packit 6c4009
  ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr)
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's word for ITEM.  */
Packit 6c4009
#define _NL_CURRENT_WORD(category, item) \
Packit 6c4009
  ((uint32_t) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word)
Packit 6c4009
Packit 6c4009
/* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  The symbol
Packit 6c4009
   _nl_current_CATEGORY_used is set to a value unequal to zero to mark this
Packit 6c4009
   category as used.  On S390 the used relocation to load the symbol address
Packit 6c4009
   can only handle even addresses.  */
Packit 6c4009
#define _NL_CURRENT_DEFINE(category) \
Packit 6c4009
  __thread struct __locale_data *const *_nl_current_##category \
Packit 6c4009
    attribute_hidden = &_nl_global_locale.__locales[category]; \
Packit 6c4009
  asm (".globl " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
Packit 6c4009
       _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 2));
Packit 6c4009
#ifdef HAVE_ASM_SET_DIRECTIVE
Packit 6c4009
# define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val
Packit 6c4009
#else
Packit 6c4009
# define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#else
Packit 6c4009
Packit 6c4009
/* All categories are always loaded in the shared library, so there is no
Packit 6c4009
   point in having lots of separate symbols for linking.  */
Packit 6c4009
Packit 6c4009
/* Return a pointer to the current `struct __locale_data' for CATEGORY.  */
Packit 6c4009
# define _NL_CURRENT_DATA(category) \
Packit 6c4009
  (_NL_CURRENT_LOCALE->__locales[category])
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's string for ITEM.  */
Packit 6c4009
# define _NL_CURRENT(category, item) \
Packit 6c4009
  (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's string for ITEM.  */
Packit 6c4009
# define _NL_CURRENT_WSTR(category, item) \
Packit 6c4009
  ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
Packit 6c4009
Packit 6c4009
/* Extract the current CATEGORY locale's word for ITEM.  */
Packit 6c4009
# define _NL_CURRENT_WORD(category, item) \
Packit 6c4009
  ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
Packit 6c4009
Packit 6c4009
/* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  */
Packit 6c4009
# define _NL_CURRENT_DEFINE(category) \
Packit 6c4009
  /* No per-category variable here. */
Packit 6c4009
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
/* Extract CATEGORY locale's string for ITEM.  */
Packit 6c4009
static inline const char *
Packit 6c4009
_nl_lookup (locale_t l, int category, int item)
Packit 6c4009
{
Packit 6c4009
  return l->__locales[category]->values[_NL_ITEM_INDEX (item)].string;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Extract CATEGORY locale's wide string for ITEM.  */
Packit 6c4009
static inline const wchar_t *
Packit 6c4009
_nl_lookup_wstr (locale_t l, int category, int item)
Packit 6c4009
{
Packit 6c4009
  return (wchar_t *) l->__locales[category]
Packit 6c4009
    ->values[_NL_ITEM_INDEX (item)].wstr;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Extract the CATEGORY locale's word for ITEM.  */
Packit 6c4009
static inline uint32_t
Packit 6c4009
_nl_lookup_word (locale_t l, int category, int item)
Packit 6c4009
{
Packit 6c4009
  return l->__locales[category]->values[_NL_ITEM_INDEX (item)].word;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* Default search path if no LOCPATH environment variable.  */
Packit 6c4009
extern const char _nl_default_locale_path[] attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Load the locale data for CATEGORY from the file specified by *NAME.
Packit 6c4009
   If *NAME is "", use environment variables as specified by POSIX, and
Packit 6c4009
   fill in *NAME with the actual name used.  If LOCALE_PATH is not null,
Packit 6c4009
   those directories are searched for the locale files.  If it's null,
Packit 6c4009
   the locale archive is checked first and then _nl_default_locale_path
Packit 6c4009
   is searched for locale files.  */
Packit 6c4009
extern struct __locale_data *_nl_find_locale (const char *locale_path,
Packit 6c4009
					      size_t locale_path_len,
Packit 6c4009
					      int category, const char **name)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Try to load the file described by FILE.  */
Packit 6c4009
extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Free all resource.  */
Packit 6c4009
extern void _nl_unload_locale (struct __locale_data *locale) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Free the locale and give back all memory if the usage count is one.  */
Packit 6c4009
extern void _nl_remove_locale (int locale, struct __locale_data *data)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Find the locale *NAMEP in the locale archive, and return the
Packit 6c4009
   internalized data structure for its CATEGORY data.  If this locale has
Packit 6c4009
   already been loaded from the archive, just returns the existing data
Packit 6c4009
   structure.  If successful, sets *NAMEP to point directly into the mapped
Packit 6c4009
   archive string table; that way, the next call can short-circuit strcmp.  */
Packit 6c4009
extern struct __locale_data *_nl_load_locale_from_archive (int category,
Packit 6c4009
							   const char **namep)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Subroutine of setlocale's __libc_subfreeres hook.  */
Packit 6c4009
extern void _nl_archive_subfreeres (void) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Subroutine of gconv-db's __libc_subfreeres hook.  */
Packit 6c4009
extern void _nl_locale_subfreeres (void) attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Validate the contents of a locale file and set up the in-core
Packit 6c4009
   data structure to point into the data.  This leaves the `alloc'
Packit 6c4009
   and `name' fields uninitialized, for the caller to fill in.
Packit 6c4009
   If any bogons are detected in the data, this will refuse to
Packit 6c4009
   intern it, and return a null pointer instead.  */
Packit 6c4009
extern struct __locale_data *_nl_intern_locale_data (int category,
Packit 6c4009
						     const void *data,
Packit 6c4009
						     size_t datasize)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* Return `era' entry which corresponds to TP.  Used in strftime.  */
Packit 6c4009
extern struct era_entry *_nl_get_era_entry (const struct tm *tp,
Packit 6c4009
					    struct __locale_data *lc_time)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Return `era' cnt'th entry .  Used in strptime.  */
Packit 6c4009
extern struct era_entry *_nl_select_era_entry (int cnt,
Packit 6c4009
					       struct __locale_data *lc_time)
Packit 6c4009
	  attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Return `alt_digit' which corresponds to NUMBER.  Used in strftime.  */
Packit 6c4009
extern const char *_nl_get_alt_digit (unsigned int number,
Packit 6c4009
				      struct __locale_data *lc_time)
Packit 6c4009
	  attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Similar, but now for wide characters.  */
Packit 6c4009
extern const wchar_t *_nl_get_walt_digit (unsigned int number,
Packit 6c4009
					  struct __locale_data *lc_time)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Parse string as alternative digit and return numeric value.  */
Packit 6c4009
extern int _nl_parse_alt_digit (const char **strp,
Packit 6c4009
				struct __locale_data *lc_time)
Packit 6c4009
     attribute_hidden;
Packit 6c4009
Packit 6c4009
/* Postload processing.  */
Packit 6c4009
extern void _nl_postload_ctype (void);
Packit 6c4009
Packit 6c4009
/* Functions used for the `private.cleanup' hook.  */
Packit 6c4009
extern void _nl_cleanup_time (struct __locale_data *) attribute_hidden;
Packit 6c4009
Packit 6c4009
Packit 6c4009
#endif	/* localeinfo.h */