2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _XLOCALE_PRIVATE_H_
25 #define _XLOCALE_PRIVATE_H_
27 #include <sys/cdefs.h>
31 #include <libkern/OSAtomic.h>
33 #include "setlocale.h"
36 #include "lmessages.h"
37 #include "lmonetary.h"
39 #include "timelocal.h"
42 #define MB_CUR_MAX (__current_locale()->__lc_ctype->__mb_cur_max)
44 #define MB_CUR_MAX_L(x) ((x)->__lc_ctype->__mb_cur_max)
46 extern int __is_threaded
;
48 typedef void (*__free_extra_t
)(void *);
50 #define XPERMANENT ((__free_extra_t)-1)
51 #define XMAGIC 0x786c6f63616c6530LL /* 'xlocale0' */
53 #define __STRUCT_COMMON \
55 __free_extra_t __free_extra;
57 struct __xlocale_st_collate
{
59 char __encoding
[ENCODING_LEN
+ 1];
60 unsigned char __substitute_table
[UCHAR_MAX
+ 1][STR_LEN
];
61 struct __collate_st_char_pri __char_pri_table
[UCHAR_MAX
+ 1];
62 struct __collate_st_chain_pri
*__chain_pri_table
;
64 struct __xlocale_st_runelocale
{
66 char __ctype_encoding
[ENCODING_LEN
+ 1];
68 size_t (*__mbrtowc
)(wchar_t * __restrict
, const char * __restrict
,
69 size_t, __darwin_mbstate_t
* __restrict
, struct _xlocale
*);
70 int (*__mbsinit
)(const __darwin_mbstate_t
*, struct _xlocale
*);
71 size_t (*__mbsnrtowcs
)(wchar_t * __restrict
, const char ** __restrict
,
72 size_t, size_t, __darwin_mbstate_t
* __restrict
, struct _xlocale
*);
73 size_t (*__wcrtomb
)(char * __restrict
, wchar_t,
74 __darwin_mbstate_t
* __restrict
, struct _xlocale
*);
75 size_t (*__wcsnrtombs
)(char * __restrict
, const wchar_t ** __restrict
,
76 size_t, size_t, __darwin_mbstate_t
* __restrict
, struct _xlocale
*);
78 _RuneLocale _CurrentRuneLocale
;
80 struct __xlocale_st_ldpart
{
85 * the next four structures must have the first three fields of the same
86 * as the _xlocale_st_ldpart structure above.
88 struct __xlocale_st_messages
{
90 char *_messages_locale_buf
;
91 struct lc_messages_T _messages_locale
;
93 struct __xlocale_st_monetary
{
95 char *_monetary_locale_buf
;
96 struct lc_monetary_T _monetary_locale
;
98 struct __xlocale_st_numeric
{
100 char *_numeric_locale_buf
;
101 struct lc_numeric_T _numeric_locale
;
103 struct __xlocale_st_time
{
105 char *_time_locale_buf
;
106 struct lc_time_T _time_locale
;
109 struct __xlocale_st_localeconv
{
114 /* the extended locale structure */
116 /* The item(s) before __magic are not copied when duplicating locale_t's */
117 /* 10 independent mbstate_t buffers! */
118 __darwin_mbstate_t __mbs_mblen
;
119 __darwin_mbstate_t __mbs_mbrlen
;
120 __darwin_mbstate_t __mbs_mbrtowc
;
121 __darwin_mbstate_t __mbs_mbsnrtowcs
;
122 __darwin_mbstate_t __mbs_mbsrtowcs
;
123 __darwin_mbstate_t __mbs_mbtowc
;
124 __darwin_mbstate_t __mbs_wcrtomb
;
125 __darwin_mbstate_t __mbs_wcsnrtombs
;
126 __darwin_mbstate_t __mbs_wcsrtombs
;
127 __darwin_mbstate_t __mbs_wctomb
;
128 /* magic (Here up to the end is copied when duplicating locale_t's) */
131 unsigned char __collate_load_error
;
132 unsigned char __collate_substitute_nontrivial
;
133 unsigned char _messages_using_locale
;
134 unsigned char _monetary_using_locale
;
135 unsigned char _numeric_using_locale
;
136 unsigned char _time_using_locale
;
137 unsigned char __mlocale_changed
;
138 unsigned char __nlocale_changed
;
140 struct __xlocale_st_collate
*__lc_collate
;
142 struct __xlocale_st_runelocale
*__lc_ctype
;
144 struct __xlocale_st_messages
*__lc_messages
;
146 struct __xlocale_st_monetary
*__lc_monetary
;
148 struct __xlocale_st_numeric
*__lc_numeric
;
150 struct __xlocale_st_time
*__lc_time
;
152 struct __xlocale_st_localeconv
*__lc_localeconv
;
155 #define NORMALIZE_LOCALE(x) if ((x) == NULL) { \
157 } else if ((x) == LC_GLOBAL_LOCALE) { \
158 (x) = &__global_locale; \
161 #define XL_RELEASE(x) if ((x) && (x)->__free_extra != XPERMANENT && OSAtomicDecrement32Barrier(&(x)->__refcount) <= 0) { \
162 if ((x)->__free_extra) \
163 (*(x)->__free_extra)((x)); \
166 #define XL_RETAIN(x) if ((x) && (x)->__free_extra != XPERMANENT) { OSAtomicIncrement32Barrier(&(x)->__refcount); }
168 __private_extern__
struct __xlocale_st_runelocale _DefaultRuneXLocale
;
169 __private_extern__
struct _xlocale __global_locale
;
170 __private_extern__ pthread_key_t __locale_key
;
174 void __ldpart_free_extra(struct __xlocale_st_ldpart
*);
175 void __xlocale_init(void);
177 static inline __attribute__((always_inline
)) locale_t
178 __current_locale(void)
180 locale_t __locale
= (locale_t
)pthread_getspecific(__locale_key
);
181 return (__locale
? __locale
: &__global_locale
);
184 static inline __attribute__((always_inline
)) locale_t
185 __locale_ptr(locale_t __loc
)
187 return (__loc
== LC_GLOBAL_LOCALE
? &__global_locale
: __loc
);
192 #endif /* _XLOCALE_PRIVATE_H_ */