Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / locale / setlocale.h
blobe91034ac85fba3f3f649b5520022a7891ed36740
1 /*-
2 * Copyright (C) 1997 by Andrey A. Chernov, Moscow, Russia.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD: src/lib/libc/locale/setlocale.h,v 1.4 2001/12/20 18:28:52 phantom Exp $
29 #ifndef _SETLOCALE_H_
30 #define _SETLOCALE_H_
32 #include <_ansi.h>
33 #include <sys/cdefs.h>
34 #include <limits.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <wchar.h>
38 #include <locale.h>
40 __BEGIN_DECLS
42 #define ENCODING_LEN 31
43 #define CATEGORY_LEN 11
44 #define _LC_LAST 7
46 #ifdef __CYGWIN__
47 struct lc_collate_T
49 wchar_t win_locale[ENCODING_LEN + 1];
50 int (*mbtowc) (struct _reent *, wchar_t *, const char *, size_t,
51 mbstate_t *);
52 char codeset[ENCODING_LEN + 1];
54 extern const struct lc_collate_T _C_collate_locale;
55 #endif
57 struct lc_ctype_T
59 const char *codeset; /* codeset for mbtowc conversion */
60 const char *mb_cur_max;
61 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
62 const char *outdigits[10];
63 const wchar_t *woutdigits[10];
64 #endif
66 extern const struct lc_ctype_T _C_ctype_locale;
67 #ifdef __CYGWIN__
68 extern const struct lc_ctype_T _C_utf8_ctype_locale;
69 #endif
71 struct lc_monetary_T
73 const char *int_curr_symbol;
74 const char *currency_symbol;
75 const char *mon_decimal_point;
76 const char *mon_thousands_sep;
77 const char *mon_grouping;
78 const char *positive_sign;
79 const char *negative_sign;
80 const char *int_frac_digits;
81 const char *frac_digits;
82 const char *p_cs_precedes;
83 const char *p_sep_by_space;
84 const char *n_cs_precedes;
85 const char *n_sep_by_space;
86 const char *p_sign_posn;
87 const char *n_sign_posn;
88 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
89 const char *int_p_cs_precedes;
90 const char *int_p_sep_by_space;
91 const char *int_n_cs_precedes;
92 const char *int_n_sep_by_space;
93 const char *int_p_sign_posn;
94 const char *int_n_sign_posn;
95 const char *codeset; /* codeset for mbtowc conversion */
96 const wchar_t *wint_curr_symbol;
97 const wchar_t *wcurrency_symbol;
98 const wchar_t *wmon_decimal_point;
99 const wchar_t *wmon_thousands_sep;
100 const wchar_t *wpositive_sign;
101 const wchar_t *wnegative_sign;
102 #endif
104 extern const struct lc_monetary_T _C_monetary_locale;
106 struct lc_numeric_T
108 const char *decimal_point;
109 const char *thousands_sep;
110 const char *grouping;
111 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
112 const char *codeset; /* codeset for mbtowc conversion */
113 const wchar_t *wdecimal_point;
114 const wchar_t *wthousands_sep;
115 #endif
117 extern const struct lc_numeric_T _C_numeric_locale;
119 struct lc_time_T
121 const char *mon[12];
122 const char *month[12];
123 const char *wday[7];
124 const char *weekday[7];
125 const char *X_fmt;
126 const char *x_fmt;
127 const char *c_fmt;
128 const char *am_pm[2];
129 const char *date_fmt;
130 const char *alt_month[12]; /* unused */
131 const char *md_order;
132 const char *ampm_fmt;
133 const char *era;
134 const char *era_d_fmt;
135 const char *era_d_t_fmt;
136 const char *era_t_fmt;
137 const char *alt_digits;
138 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
139 const char *codeset; /* codeset for mbtowc conversion */
140 const wchar_t *wmon[12];
141 const wchar_t *wmonth[12];
142 const wchar_t *wwday[7];
143 const wchar_t *wweekday[7];
144 const wchar_t *wX_fmt;
145 const wchar_t *wx_fmt;
146 const wchar_t *wc_fmt;
147 const wchar_t *wam_pm[2];
148 const wchar_t *wdate_fmt;
149 const wchar_t *wampm_fmt;
150 const wchar_t *wera;
151 const wchar_t *wera_d_fmt;
152 const wchar_t *wera_d_t_fmt;
153 const wchar_t *wera_t_fmt;
154 const wchar_t *walt_digits;
155 #endif
157 extern const struct lc_time_T _C_time_locale;
159 struct lc_messages_T
161 const char *yesexpr;
162 const char *noexpr;
163 const char *yesstr;
164 const char *nostr;
165 #ifdef __HAVE_LOCALE_INFO__
166 const char *codeset; /* codeset for mbtowc conversion */
167 #ifdef __HAVE_LOCALE_INFO_EXTENDED__
168 const wchar_t *wyesexpr;
169 const wchar_t *wnoexpr;
170 const wchar_t *wyesstr;
171 const wchar_t *wnostr;
172 #endif
173 #endif
175 extern const struct lc_messages_T _C_messages_locale;
177 struct __lc_cats
179 const void *ptr;
180 char *buf;
183 struct __locale_t
185 char categories[_LC_LAST][ENCODING_LEN + 1];
186 int (*wctomb) (struct _reent *, char *, wchar_t,
187 mbstate_t *);
188 int (*mbtowc) (struct _reent *, wchar_t *,
189 const char *, size_t, mbstate_t *);
190 int cjk_lang;
191 char *ctype_ptr;
192 struct lconv lconv;
193 #ifndef __HAVE_LOCALE_INFO__
194 char mb_cur_max[2];
195 char ctype_codeset[ENCODING_LEN + 1];
196 char message_codeset[ENCODING_LEN + 1];
197 #else
198 struct __lc_cats lc_cat[_LC_LAST];
199 #endif
202 #ifdef _MB_CAPABLE
203 extern char *__loadlocale (struct __locale_t *, int, char *);
204 extern const char *__get_locale_env(struct _reent *, int);
205 #endif /* _MB_CAPABLE */
207 extern struct lconv *__localeconv_l (struct __locale_t *locale);
209 extern size_t _wcsnrtombs_l (struct _reent *, char *, const wchar_t **,
210 size_t, size_t, mbstate_t *, struct __locale_t *);
212 /* In POSIX terms the global locale is the process-wide locale. Use this
213 function to always refer to the global locale. */
214 _ELIDABLE_INLINE struct __locale_t *
215 __get_global_locale ()
217 extern struct __locale_t __global_locale;
218 return &__global_locale;
221 /* Per REENT locale. This is newlib-internal. */
222 _ELIDABLE_INLINE struct __locale_t *
223 __get_locale_r (struct _reent *r)
225 #ifdef __HAVE_LOCALE_INFO__
226 return _REENT_LOCALE(r);
227 #else
228 return __get_global_locale();
229 #endif
232 /* In POSIX terms the current locale is the locale used by all functions
233 using locale info without providing a locale as parameter (*_l functions).
234 The current locale is either the locale of the current thread, if the
235 thread called uselocale, or the global locale if not. */
236 _ELIDABLE_INLINE struct __locale_t *
237 __get_current_locale (void)
239 #ifdef __HAVE_LOCALE_INFO__
240 return _REENT_LOCALE(_REENT) ?: __get_global_locale ();
241 #else
242 return __get_global_locale();
243 #endif
246 /* Only access fixed "C" locale using this function. Fake for !_MB_CAPABLE
247 targets by returning ptr to globale locale. */
248 _ELIDABLE_INLINE struct __locale_t *
249 __get_C_locale (void)
251 #ifndef _MB_CAPABLE
252 return __get_global_locale ();
253 #else
254 extern const struct __locale_t __C_locale;
255 return (struct __locale_t *) &__C_locale;
256 #endif
259 #ifdef __CYGWIN__
260 _ELIDABLE_INLINE const struct lc_collate_T *
261 __get_collate_locale (struct __locale_t *locale)
263 return (const struct lc_collate_T *) locale->lc_cat[LC_COLLATE].ptr;
266 _ELIDABLE_INLINE const struct lc_collate_T *
267 __get_current_collate_locale (void)
269 return (const struct lc_collate_T *)
270 __get_current_locale ()->lc_cat[LC_COLLATE].ptr;
272 #endif
274 #ifdef __HAVE_LOCALE_INFO__
275 _ELIDABLE_INLINE const struct lc_ctype_T *
276 __get_ctype_locale (struct __locale_t *locale)
278 return (const struct lc_ctype_T *) (locale)->lc_cat[LC_CTYPE].ptr;
281 _ELIDABLE_INLINE const struct lc_ctype_T *
282 __get_current_ctype_locale (void)
284 return (const struct lc_ctype_T *)
285 __get_current_locale ()->lc_cat[LC_CTYPE].ptr;
287 #endif
289 _ELIDABLE_INLINE int
290 __locale_mb_cur_max_l (struct __locale_t *locale)
292 #ifdef __HAVE_LOCALE_INFO__
293 return __get_ctype_locale (locale)->mb_cur_max[0];
294 #else
295 return locale->mb_cur_max[0];
296 #endif
299 #ifdef __HAVE_LOCALE_INFO__
300 _ELIDABLE_INLINE const struct lc_monetary_T *
301 __get_monetary_locale (struct __locale_t *locale)
303 return (const struct lc_monetary_T *) (locale)->lc_cat[LC_MONETARY].ptr;
306 _ELIDABLE_INLINE const struct lc_monetary_T *
307 __get_current_monetary_locale (void)
309 return (const struct lc_monetary_T *)
310 __get_current_locale ()->lc_cat[LC_MONETARY].ptr;
313 _ELIDABLE_INLINE const struct lc_numeric_T *
314 __get_numeric_locale (struct __locale_t *locale)
316 return (const struct lc_numeric_T *) (locale)->lc_cat[LC_NUMERIC].ptr;
319 _ELIDABLE_INLINE const struct lc_numeric_T *
320 __get_current_numeric_locale (void)
322 return (const struct lc_numeric_T *)
323 __get_current_locale ()->lc_cat[LC_NUMERIC].ptr;
326 _ELIDABLE_INLINE const struct lc_time_T *
327 __get_time_locale (struct __locale_t *locale)
329 return (const struct lc_time_T *) (locale)->lc_cat[LC_TIME].ptr;
332 _ELIDABLE_INLINE const struct lc_time_T *
333 __get_current_time_locale (void)
335 return (const struct lc_time_T *)
336 __get_current_locale ()->lc_cat[LC_TIME].ptr;
339 _ELIDABLE_INLINE const struct lc_messages_T *
340 __get_messages_locale (struct __locale_t *locale)
342 return (const struct lc_messages_T *) (locale)->lc_cat[LC_MESSAGES].ptr;
345 _ELIDABLE_INLINE const struct lc_messages_T *
346 __get_current_messages_locale (void)
348 return (const struct lc_messages_T *)
349 __get_current_locale ()->lc_cat[LC_MESSAGES].ptr;
351 #else /* ! __HAVE_LOCALE_INFO__ */
352 _ELIDABLE_INLINE const struct lc_monetary_T *
353 __get_monetary_locale (struct __locale_t *locale)
355 return &_C_monetary_locale;
358 _ELIDABLE_INLINE const struct lc_monetary_T *
359 __get_current_monetary_locale (void)
361 return &_C_monetary_locale;
364 _ELIDABLE_INLINE const struct lc_numeric_T *
365 __get_numeric_locale (struct __locale_t *locale)
367 return &_C_numeric_locale;
370 _ELIDABLE_INLINE const struct lc_numeric_T *
371 __get_current_numeric_locale (void)
373 return &_C_numeric_locale;
376 _ELIDABLE_INLINE const struct lc_time_T *
377 __get_time_locale (struct __locale_t *locale)
379 return &_C_time_locale;
382 _ELIDABLE_INLINE const struct lc_time_T *
383 __get_current_time_locale (void)
385 return &_C_time_locale;
388 _ELIDABLE_INLINE const struct lc_messages_T *
389 __get_messages_locale (struct __locale_t *locale)
391 return &_C_messages_locale;
394 _ELIDABLE_INLINE const struct lc_messages_T *
395 __get_current_messages_locale (void)
397 return &_C_messages_locale;
399 #endif /* !__HAVE_LOCALE_INFO__ */
401 _ELIDABLE_INLINE const char *
402 __locale_charset (struct __locale_t *locale)
404 #ifdef __HAVE_LOCALE_INFO__
405 return __get_ctype_locale (locale)->codeset;
406 #else
407 return locale->ctype_codeset;
408 #endif
411 _ELIDABLE_INLINE const char *
412 __current_locale_charset (void)
414 #ifdef __HAVE_LOCALE_INFO__
415 return __get_current_ctype_locale ()->codeset;
416 #else
417 return __get_current_locale ()->ctype_codeset;
418 #endif
421 _ELIDABLE_INLINE const char *
422 __locale_msgcharset (void)
424 #ifdef __HAVE_LOCALE_INFO__
425 return (char *) __get_current_messages_locale ()->codeset;
426 #else
427 return (char *) __get_current_locale ()->message_codeset;
428 #endif
431 _ELIDABLE_INLINE int
432 __locale_cjk_lang (void)
434 return __get_current_locale ()->cjk_lang;
437 int __ctype_load_locale (struct __locale_t *, const char *, void *,
438 const char *, int);
439 int __monetary_load_locale (struct __locale_t *, const char *, void *,
440 const char *);
441 int __numeric_load_locale (struct __locale_t *, const char *, void *,
442 const char *);
443 int __time_load_locale (struct __locale_t *, const char *, void *,
444 const char *);
445 int __messages_load_locale (struct __locale_t *, const char *, void *,
446 const char *);
447 #ifdef __CYGWIN__
448 int __collate_load_locale (struct __locale_t *, const char *, void *,
449 const char *);
451 extern void __set_charset_from_locale (const char *locale, char *charset);
452 extern char *__set_locale_from_locale_alias (const char *, char *);
453 #endif
455 __END_DECLS
457 #endif /* !_SETLOCALE_H_ */