Remove _dl_initial_dtv
[glibc.git] / locale / localeinfo.h
blob39c15989f222d8489bef7f942be6f6938920b452
1 /* Declarations for internal libc locale interfaces
2 Copyright (C) 1995-2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef _LOCALEINFO_H
21 #define _LOCALEINFO_H 1
23 #include <stddef.h>
24 #include <langinfo.h>
25 #include <limits.h>
26 #include <locale.h>
27 #include <time.h>
28 #include <stdint.h>
29 #include <sys/types.h>
31 #include <intl/loadinfo.h> /* For loaded_l10nfile definition. */
33 /* Magic number at the beginning of a locale data file for CATEGORY. */
34 #define LIMAGIC(category) \
35 (category == LC_COLLATE \
36 ? ((unsigned int) (0x20051014 ^ (category))) \
37 : category == LC_CTYPE \
38 ? ((unsigned int) (0x20090720 ^ (category))) \
39 : ((unsigned int) (0x20031115 ^ (category))))
41 /* Two special weight constants for the collation data. */
42 #define IGNORE_CHAR 2
44 /* We use a special value for the usage counter in `__locale_data' to
45 signal that this data must never be removed anymore. */
46 #define MAX_USAGE_COUNT (UINT_MAX - 1)
47 #define UNDELETABLE UINT_MAX
49 /* Structure describing locale data in core for a category. */
50 struct __locale_data
52 const char *name;
53 const char *filedata; /* Region mapping the file data. */
54 off_t filesize; /* Size of the file (and the region). */
55 enum /* Flavor of storage used for those. */
57 ld_malloced, /* Both are malloc'd. */
58 ld_mapped, /* name is malloc'd, filedata mmap'd */
59 ld_archive /* Both point into mmap'd archive regions. */
60 } alloc;
62 /* This provides a slot for category-specific code to cache data computed
63 about this locale. That code can set a cleanup function to deallocate
64 the data. */
65 struct
67 void (*cleanup) (struct __locale_data *) internal_function;
68 union
70 void *data;
71 struct lc_time_data *time;
72 const struct gconv_fcts *ctype;
74 } private;
76 unsigned int usage_count; /* Counter for users. */
78 int use_translit; /* Nonzero if the mb*towv*() and wc*tomb()
79 functions should use transliteration. */
81 unsigned int nstrings; /* Number of strings below. */
82 union locale_data_value
84 const uint32_t *wstr;
85 const char *string;
86 unsigned int word; /* Note endian issues vs 64-bit pointers. */
88 values __flexarr; /* Items, usually pointers into `filedata'. */
91 /* We know three kinds of collation sorting rules. */
92 enum coll_sort_rule
94 illegal_0__,
95 sort_forward,
96 sort_backward,
97 illegal_3__,
98 sort_position,
99 sort_forward_position,
100 sort_backward_position,
101 sort_mask
104 /* We can map the types of the entries into a few categories. */
105 enum value_type
107 none,
108 string,
109 stringarray,
110 byte,
111 bytearray,
112 word,
113 stringlist,
114 wordarray,
115 wstring,
116 wstringarray,
117 wstringlist
121 /* Definitions for `era' information from LC_TIME. */
122 #define ERA_NAME_FORMAT_MEMBERS 4
123 #define ERA_M_NAME 0
124 #define ERA_M_FORMAT 1
125 #define ERA_W_NAME 2
126 #define ERA_W_FORMAT 3
129 /* Structure to access `era' information from LC_TIME. */
130 struct era_entry
132 uint32_t direction; /* Contains '+' or '-'. */
133 int32_t offset;
134 int32_t start_date[3];
135 int32_t stop_date[3];
136 const char *era_name;
137 const char *era_format;
138 const wchar_t *era_wname;
139 const wchar_t *era_wformat;
140 int absolute_direction;
141 /* absolute direction:
142 +1 indicates that year number is higher in the future. (like A.D.)
143 -1 indicates that year number is higher in the past. (like B.C.) */
146 /* Structure caching computed data about information from LC_TIME.
147 The `private.time' member of `struct __locale_data' points to this. */
148 struct lc_time_data
150 struct era_entry *eras;
151 size_t num_eras;
152 int era_initialized;
154 const char **alt_digits;
155 const wchar_t **walt_digits;
156 int alt_digits_initialized;
157 int walt_digits_initialized;
161 /* LC_CTYPE specific:
162 Hardwired indices for standard wide character translation mappings. */
163 enum
165 __TOW_toupper = 0,
166 __TOW_tolower = 1
170 /* LC_CTYPE specific:
171 Access a wide character class with a single character index.
172 _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
173 c must be an `unsigned char'. desc must be a nonzero wctype_t. */
174 #define _ISCTYPE(c, desc) \
175 (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
177 /* Category name handling variables. */
178 #define CATNAMEMF(line) CATNAMEMF1 (line)
179 #define CATNAMEMF1(line) str##line
180 extern const union catnamestr_t
182 struct
184 #define DEFINE_CATEGORY(category, category_name, items, a) \
185 char CATNAMEMF (__LINE__)[sizeof (category_name)];
186 #include "categories.def"
187 #undef DEFINE_CATEGORY
189 char str[0];
190 } _nl_category_names attribute_hidden;
191 extern const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden;
192 extern const uint8_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
194 /* Name of the standard locales. */
195 extern const char _nl_C_name[] attribute_hidden;
196 extern const char _nl_POSIX_name[] attribute_hidden;
198 /* The standard codeset. */
199 extern const char _nl_C_codeset[] attribute_hidden;
201 /* This is the internal locale_t object that holds the global locale
202 controlled by calls to setlocale. A thread's TSD locale pointer
203 points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */
204 extern struct __locale_struct _nl_global_locale attribute_hidden;
206 /* This fetches the thread-local locale_t pointer, either one set with
207 uselocale or &_nl_global_locale. */
208 #define _NL_CURRENT_LOCALE (__libc_tsd_get (__locale_t, LOCALE))
209 #include <bits/libc-tsd.h>
210 __libc_tsd_define (extern, __locale_t, LOCALE)
213 /* For static linking it is desireable to avoid always linking in the code
214 and data for every category when we can tell at link time that they are
215 unused. We can manage this playing some tricks with weak references.
216 But with thread-local locale settings, it becomes quite ungainly unless
217 we can use __thread variables. So only in that case do we attempt this. */
218 #ifndef SHARED
219 # include <tls.h>
220 # define NL_CURRENT_INDIRECT 1
221 #endif
223 #ifdef NL_CURRENT_INDIRECT
225 /* For each category declare the thread-local variable for the current
226 locale data. This has an extra indirection so it points at the
227 __locales[CATEGORY] element in either _nl_global_locale or the current
228 locale object set by uselocale, which points at the actual data. The
229 reason for having these variables is so that references to particular
230 categories will link in the lc-CATEGORY.c module to define this symbol,
231 and we arrange that linking that module is what brings in all the code
232 associated with this category. */
233 #define DEFINE_CATEGORY(category, category_name, items, a) \
234 extern __thread struct __locale_data *const *_nl_current_##category \
235 attribute_hidden attribute_tls_model_ie;
236 #include "categories.def"
237 #undef DEFINE_CATEGORY
239 /* Return a pointer to the current `struct __locale_data' for CATEGORY. */
240 #define _NL_CURRENT_DATA(category) (*_nl_current_##category)
242 /* Extract the current CATEGORY locale's string for ITEM. */
243 #define _NL_CURRENT(category, item) \
244 ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string)
246 /* Extract the current CATEGORY locale's string for ITEM. */
247 #define _NL_CURRENT_WSTR(category, item) \
248 ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr)
250 /* Extract the current CATEGORY locale's word for ITEM. */
251 #define _NL_CURRENT_WORD(category, item) \
252 ((uint32_t) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word)
254 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
255 #define _NL_CURRENT_DEFINE(category) \
256 __thread struct __locale_data *const *_nl_current_##category \
257 attribute_hidden = &_nl_global_locale.__locales[category]; \
258 asm (".globl " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
259 _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 1));
260 #ifdef HAVE_ASM_SET_DIRECTIVE
261 # define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val
262 #else
263 # define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val
264 #endif
266 #else
268 /* All categories are always loaded in the shared library, so there is no
269 point in having lots of separate symbols for linking. */
271 /* Return a pointer to the current `struct __locale_data' for CATEGORY. */
272 # define _NL_CURRENT_DATA(category) \
273 (_NL_CURRENT_LOCALE->__locales[category])
275 /* Extract the current CATEGORY locale's string for ITEM. */
276 # define _NL_CURRENT(category, item) \
277 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
279 /* Extract the current CATEGORY locale's string for ITEM. */
280 # define _NL_CURRENT_WSTR(category, item) \
281 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
283 /* Extract the current CATEGORY locale's word for ITEM. */
284 # define _NL_CURRENT_WORD(category, item) \
285 ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
287 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
288 # define _NL_CURRENT_DEFINE(category) \
289 /* No per-category variable here. */
291 #endif
294 /* Default search path if no LOCPATH environment variable. */
295 extern const char _nl_default_locale_path[] attribute_hidden;
297 /* Load the locale data for CATEGORY from the file specified by *NAME.
298 If *NAME is "", use environment variables as specified by POSIX, and
299 fill in *NAME with the actual name used. If LOCALE_PATH is not null,
300 those directories are searched for the locale files. If it's null,
301 the locale archive is checked first and then _nl_default_locale_path
302 is searched for locale files. */
303 extern struct __locale_data *_nl_find_locale (const char *locale_path,
304 size_t locale_path_len,
305 int category, const char **name)
306 internal_function attribute_hidden;
308 /* Try to load the file described by FILE. */
309 extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
310 internal_function attribute_hidden;
312 /* Free all resource. */
313 extern void _nl_unload_locale (struct __locale_data *locale)
314 internal_function attribute_hidden;
316 /* Free the locale and give back all memory if the usage count is one. */
317 extern void _nl_remove_locale (int locale, struct __locale_data *data)
318 internal_function attribute_hidden;
320 /* Find the locale *NAMEP in the locale archive, and return the
321 internalized data structure for its CATEGORY data. If this locale has
322 already been loaded from the archive, just returns the existing data
323 structure. If successful, sets *NAMEP to point directly into the mapped
324 archive string table; that way, the next call can short-circuit strcmp. */
325 extern struct __locale_data *_nl_load_locale_from_archive (int category,
326 const char **namep)
327 internal_function attribute_hidden;
329 /* Subroutine of setlocale's __libc_subfreeres hook. */
330 extern void _nl_archive_subfreeres (void) attribute_hidden;
332 /* Subroutine of gconv-db's __libc_subfreeres hook. */
333 extern void _nl_locale_subfreeres (void) attribute_hidden;
335 /* Validate the contents of a locale file and set up the in-core
336 data structure to point into the data. This leaves the `alloc'
337 and `name' fields uninitialized, for the caller to fill in.
338 If any bogons are detected in the data, this will refuse to
339 intern it, and return a null pointer instead. */
340 extern struct __locale_data *_nl_intern_locale_data (int category,
341 const void *data,
342 size_t datasize)
343 internal_function attribute_hidden;
346 /* Return `era' entry which corresponds to TP. Used in strftime. */
347 extern struct era_entry *_nl_get_era_entry (const struct tm *tp,
348 struct __locale_data *lc_time)
349 internal_function attribute_hidden;
351 /* Return `era' cnt'th entry . Used in strptime. */
352 extern struct era_entry *_nl_select_era_entry (int cnt,
353 struct __locale_data *lc_time)
354 internal_function attribute_hidden;
356 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
357 extern const char *_nl_get_alt_digit (unsigned int number,
358 struct __locale_data *lc_time)
359 internal_function attribute_hidden;
361 /* Similar, but now for wide characters. */
362 extern const wchar_t *_nl_get_walt_digit (unsigned int number,
363 struct __locale_data *lc_time)
364 internal_function attribute_hidden;
366 /* Parse string as alternative digit and return numeric value. */
367 extern int _nl_parse_alt_digit (const char **strp,
368 struct __locale_data *lc_time)
369 internal_function attribute_hidden;
371 /* Postload processing. */
372 extern void _nl_postload_ctype (void);
374 /* Functions used for the `private.cleanup' hook. */
375 extern void _nl_cleanup_time (struct __locale_data *)
376 internal_function attribute_hidden;
379 #endif /* localeinfo.h */