Remove redunant "warning: " prefix from stub warnings.
[glibc.git] / locale / localeinfo.h
blob3142726605dea2cd62ac0fff9459aa8e3b5cd811
1 /* Declarations for internal libc locale interfaces
2 Copyright (C) 1995-2013 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, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _LOCALEINFO_H
20 #define _LOCALEINFO_H 1
22 #include <stddef.h>
23 #include <langinfo.h>
24 #include <limits.h>
25 #include <locale.h>
26 #include <time.h>
27 #include <stdint.h>
28 #include <sys/types.h>
30 #include <intl/loadinfo.h> /* For loaded_l10nfile definition. */
32 /* Magic number at the beginning of a locale data file for CATEGORY. */
33 #define LIMAGIC(category) \
34 (category == LC_COLLATE \
35 ? ((unsigned int) (0x20051014 ^ (category))) \
36 : category == LC_CTYPE \
37 ? ((unsigned int) (0x20090720 ^ (category))) \
38 : ((unsigned int) (0x20031115 ^ (category))))
40 /* Two special weight constants for the collation data. */
41 #define IGNORE_CHAR 2
43 /* We use a special value for the usage counter in `__locale_data' to
44 signal that this data must never be removed anymore. */
45 #define MAX_USAGE_COUNT (UINT_MAX - 1)
46 #define UNDELETABLE UINT_MAX
48 /* Structure describing locale data in core for a category. */
49 struct __locale_data
51 const char *name;
52 const char *filedata; /* Region mapping the file data. */
53 off_t filesize; /* Size of the file (and the region). */
54 enum /* Flavor of storage used for those. */
56 ld_malloced, /* Both are malloc'd. */
57 ld_mapped, /* name is malloc'd, filedata mmap'd */
58 ld_archive /* Both point into mmap'd archive regions. */
59 } alloc;
61 /* This provides a slot for category-specific code to cache data computed
62 about this locale. That code can set a cleanup function to deallocate
63 the data. */
64 struct
66 void (*cleanup) (struct __locale_data *) internal_function;
67 union
69 void *data;
70 struct lc_time_data *time;
71 const struct gconv_fcts *ctype;
73 } private;
75 unsigned int usage_count; /* Counter for users. */
77 int use_translit; /* Nonzero if the mb*towv*() and wc*tomb()
78 functions should use transliteration. */
80 unsigned int nstrings; /* Number of strings below. */
81 union locale_data_value
83 const uint32_t *wstr;
84 const char *string;
85 unsigned int word; /* Note endian issues vs 64-bit pointers. */
87 values __flexarr; /* Items, usually pointers into `filedata'. */
90 /* We know three kinds of collation sorting rules. */
91 enum coll_sort_rule
93 illegal_0__,
94 sort_forward,
95 sort_backward,
96 illegal_3__,
97 sort_position,
98 sort_forward_position,
99 sort_backward_position,
100 sort_mask
103 /* We can map the types of the entries into a few categories. */
104 enum value_type
106 none,
107 string,
108 stringarray,
109 byte,
110 bytearray,
111 word,
112 stringlist,
113 wordarray,
114 wstring,
115 wstringarray,
116 wstringlist
120 /* Definitions for `era' information from LC_TIME. */
121 #define ERA_NAME_FORMAT_MEMBERS 4
122 #define ERA_M_NAME 0
123 #define ERA_M_FORMAT 1
124 #define ERA_W_NAME 2
125 #define ERA_W_FORMAT 3
128 /* Structure to access `era' information from LC_TIME. */
129 struct era_entry
131 uint32_t direction; /* Contains '+' or '-'. */
132 int32_t offset;
133 int32_t start_date[3];
134 int32_t stop_date[3];
135 const char *era_name;
136 const char *era_format;
137 const wchar_t *era_wname;
138 const wchar_t *era_wformat;
139 int absolute_direction;
140 /* absolute direction:
141 +1 indicates that year number is higher in the future. (like A.D.)
142 -1 indicates that year number is higher in the past. (like B.C.) */
145 /* Structure caching computed data about information from LC_TIME.
146 The `private.time' member of `struct __locale_data' points to this. */
147 struct lc_time_data
149 struct era_entry *eras;
150 size_t num_eras;
151 int era_initialized;
153 const char **alt_digits;
154 const wchar_t **walt_digits;
155 int alt_digits_initialized;
156 int walt_digits_initialized;
160 /* LC_CTYPE specific:
161 Hardwired indices for standard wide character translation mappings. */
162 enum
164 __TOW_toupper = 0,
165 __TOW_tolower = 1
169 /* LC_CTYPE specific:
170 Access a wide character class with a single character index.
171 _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
172 c must be an `unsigned char'. desc must be a nonzero wctype_t. */
173 #define _ISCTYPE(c, desc) \
174 (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
176 /* Category name handling variables. */
177 #define CATNAMEMF(line) CATNAMEMF1 (line)
178 #define CATNAMEMF1(line) str##line
179 extern const union catnamestr_t
181 struct
183 #define DEFINE_CATEGORY(category, category_name, items, a) \
184 char CATNAMEMF (__LINE__)[sizeof (category_name)];
185 #include "categories.def"
186 #undef DEFINE_CATEGORY
188 char str[0];
189 } _nl_category_names attribute_hidden;
190 extern const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden;
191 extern const uint8_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
193 /* Name of the standard locales. */
194 extern const char _nl_C_name[] attribute_hidden;
195 extern const char _nl_POSIX_name[] attribute_hidden;
197 /* The standard codeset. */
198 extern const char _nl_C_codeset[] attribute_hidden;
200 /* This is the internal locale_t object that holds the global locale
201 controlled by calls to setlocale. A thread's TSD locale pointer
202 points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */
203 extern struct __locale_struct _nl_global_locale attribute_hidden;
205 /* This fetches the thread-local locale_t pointer, either one set with
206 uselocale or &_nl_global_locale. */
207 #define _NL_CURRENT_LOCALE (__libc_tsd_get (__locale_t, LOCALE))
208 #include <bits/libc-tsd.h>
209 __libc_tsd_define (extern, __locale_t, LOCALE)
212 /* For static linking it is desireable to avoid always linking in the code
213 and data for every category when we can tell at link time that they are
214 unused. We can manage this playing some tricks with weak references.
215 But with thread-local locale settings, it becomes quite ungainly unless
216 we can use __thread variables. So only in that case do we attempt this. */
217 #ifndef SHARED
218 # include <tls.h>
219 # define NL_CURRENT_INDIRECT 1
220 #endif
222 #ifdef NL_CURRENT_INDIRECT
224 /* For each category declare the thread-local variable for the current
225 locale data. This has an extra indirection so it points at the
226 __locales[CATEGORY] element in either _nl_global_locale or the current
227 locale object set by uselocale, which points at the actual data. The
228 reason for having these variables is so that references to particular
229 categories will link in the lc-CATEGORY.c module to define this symbol,
230 and we arrange that linking that module is what brings in all the code
231 associated with this category. */
232 #define DEFINE_CATEGORY(category, category_name, items, a) \
233 extern __thread struct __locale_data *const *_nl_current_##category \
234 attribute_hidden attribute_tls_model_ie;
235 #include "categories.def"
236 #undef DEFINE_CATEGORY
238 /* Return a pointer to the current `struct __locale_data' for CATEGORY. */
239 #define _NL_CURRENT_DATA(category) (*_nl_current_##category)
241 /* Extract the current CATEGORY locale's string for ITEM. */
242 #define _NL_CURRENT(category, item) \
243 ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string)
245 /* Extract the current CATEGORY locale's string for ITEM. */
246 #define _NL_CURRENT_WSTR(category, item) \
247 ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr)
249 /* Extract the current CATEGORY locale's word for ITEM. */
250 #define _NL_CURRENT_WORD(category, item) \
251 ((uint32_t) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word)
253 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
254 #define _NL_CURRENT_DEFINE(category) \
255 __thread struct __locale_data *const *_nl_current_##category \
256 attribute_hidden = &_nl_global_locale.__locales[category]; \
257 asm (".globl " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
258 _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 1));
259 #ifdef HAVE_ASM_SET_DIRECTIVE
260 # define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val
261 #else
262 # define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val
263 #endif
265 #else
267 /* All categories are always loaded in the shared library, so there is no
268 point in having lots of separate symbols for linking. */
270 /* Return a pointer to the current `struct __locale_data' for CATEGORY. */
271 # define _NL_CURRENT_DATA(category) \
272 (_NL_CURRENT_LOCALE->__locales[category])
274 /* Extract the current CATEGORY locale's string for ITEM. */
275 # define _NL_CURRENT(category, item) \
276 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
278 /* Extract the current CATEGORY locale's string for ITEM. */
279 # define _NL_CURRENT_WSTR(category, item) \
280 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
282 /* Extract the current CATEGORY locale's word for ITEM. */
283 # define _NL_CURRENT_WORD(category, item) \
284 ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
286 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
287 # define _NL_CURRENT_DEFINE(category) \
288 /* No per-category variable here. */
290 #endif
293 /* Default search path if no LOCPATH environment variable. */
294 extern const char _nl_default_locale_path[] attribute_hidden;
296 /* Load the locale data for CATEGORY from the file specified by *NAME.
297 If *NAME is "", use environment variables as specified by POSIX, and
298 fill in *NAME with the actual name used. If LOCALE_PATH is not null,
299 those directories are searched for the locale files. If it's null,
300 the locale archive is checked first and then _nl_default_locale_path
301 is searched for locale files. */
302 extern struct __locale_data *_nl_find_locale (const char *locale_path,
303 size_t locale_path_len,
304 int category, const char **name)
305 internal_function attribute_hidden;
307 /* Try to load the file described by FILE. */
308 extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
309 internal_function attribute_hidden;
311 /* Free all resource. */
312 extern void _nl_unload_locale (struct __locale_data *locale)
313 internal_function attribute_hidden;
315 /* Free the locale and give back all memory if the usage count is one. */
316 extern void _nl_remove_locale (int locale, struct __locale_data *data)
317 internal_function attribute_hidden;
319 /* Find the locale *NAMEP in the locale archive, and return the
320 internalized data structure for its CATEGORY data. If this locale has
321 already been loaded from the archive, just returns the existing data
322 structure. If successful, sets *NAMEP to point directly into the mapped
323 archive string table; that way, the next call can short-circuit strcmp. */
324 extern struct __locale_data *_nl_load_locale_from_archive (int category,
325 const char **namep)
326 internal_function attribute_hidden;
328 /* Subroutine of setlocale's __libc_subfreeres hook. */
329 extern void _nl_archive_subfreeres (void) attribute_hidden;
331 /* Subroutine of gconv-db's __libc_subfreeres hook. */
332 extern void _nl_locale_subfreeres (void) attribute_hidden;
334 /* Validate the contents of a locale file and set up the in-core
335 data structure to point into the data. This leaves the `alloc'
336 and `name' fields uninitialized, for the caller to fill in.
337 If any bogons are detected in the data, this will refuse to
338 intern it, and return a null pointer instead. */
339 extern struct __locale_data *_nl_intern_locale_data (int category,
340 const void *data,
341 size_t datasize)
342 internal_function attribute_hidden;
345 /* Return `era' entry which corresponds to TP. Used in strftime. */
346 extern struct era_entry *_nl_get_era_entry (const struct tm *tp,
347 struct __locale_data *lc_time)
348 internal_function attribute_hidden;
350 /* Return `era' cnt'th entry . Used in strptime. */
351 extern struct era_entry *_nl_select_era_entry (int cnt,
352 struct __locale_data *lc_time)
353 internal_function attribute_hidden;
355 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
356 extern const char *_nl_get_alt_digit (unsigned int number,
357 struct __locale_data *lc_time)
358 internal_function attribute_hidden;
360 /* Similar, but now for wide characters. */
361 extern const wchar_t *_nl_get_walt_digit (unsigned int number,
362 struct __locale_data *lc_time)
363 internal_function attribute_hidden;
365 /* Parse string as alternative digit and return numeric value. */
366 extern int _nl_parse_alt_digit (const char **strp,
367 struct __locale_data *lc_time)
368 internal_function attribute_hidden;
370 /* Postload processing. */
371 extern void _nl_postload_ctype (void);
373 /* Functions used for the `private.cleanup' hook. */
374 extern void _nl_cleanup_time (struct __locale_data *)
375 internal_function attribute_hidden;
378 #endif /* localeinfo.h */