]> git.saurik.com Git - apple/libc.git/blame - locale/xlocale_private.h
Libc-391.4.3.tar.gz
[apple/libc.git] / locale / xlocale_private.h
CommitLineData
3d9156a7
A
1/*
2 * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _XLOCALE_PRIVATE_H_
25#define _XLOCALE_PRIVATE_H_
26
27#include <sys/cdefs.h>
28#include <xlocale.h>
29#include <stdlib.h>
30#include <locale.h>
31#include <libkern/OSAtomic.h>
32#include <pthread.h>
33#include "setlocale.h"
34#include "collate.h"
35#include "runetype.h"
36#include "lmessages.h"
37#include "lmonetary.h"
38#include "lnumeric.h"
39#include "timelocal.h"
40
41#undef MB_CUR_MAX
42#define MB_CUR_MAX (__current_locale()->__lc_ctype->__mb_cur_max)
43#undef MB_CUR_MAX_L
44#define MB_CUR_MAX_L(x) ((x)->__lc_ctype->__mb_cur_max)
45
46extern int __is_threaded;
47
48typedef void (*__free_extra_t)(void *);
49
50#define XPERMANENT ((__free_extra_t)-1)
51#define XMAGIC 0x786c6f63616c6530LL /* 'xlocale0' */
52
53#define __STRUCT_COMMON \
54 int32_t __refcount; \
55 __free_extra_t __free_extra;
56
57struct __xlocale_st_collate {
58 __STRUCT_COMMON
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;
63};
64struct __xlocale_st_runelocale {
65 __STRUCT_COMMON
66 char __ctype_encoding[ENCODING_LEN + 1];
67 int __mb_cur_max;
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 *);
77 int __datasize;
78 _RuneLocale _CurrentRuneLocale;
79};
80struct __xlocale_st_ldpart {
81 __STRUCT_COMMON
82 char *_locale_buf;
83};
84/*
85 * the next four structures must have the first three fields of the same
86 * as the _xlocale_st_ldpart structure above.
87 */
88struct __xlocale_st_messages {
89 __STRUCT_COMMON
90 char *_messages_locale_buf;
91 struct lc_messages_T _messages_locale;
92};
93struct __xlocale_st_monetary {
94 __STRUCT_COMMON
95 char *_monetary_locale_buf;
96 struct lc_monetary_T _monetary_locale;
97};
98struct __xlocale_st_numeric {
99 __STRUCT_COMMON
100 char *_numeric_locale_buf;
101 struct lc_numeric_T _numeric_locale;
102};
103struct __xlocale_st_time {
104 __STRUCT_COMMON
105 char *_time_locale_buf;
106 struct lc_time_T _time_locale;
107};
108
109struct __xlocale_st_localeconv {
110 __STRUCT_COMMON
111 struct lconv __ret;
112};
113
114/* the extended locale structure */
115struct _xlocale {
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) */
129 int64_t __magic;
130/* flags */
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;
139/* collate */
140 struct __xlocale_st_collate *__lc_collate;
141/* ctype */
142 struct __xlocale_st_runelocale *__lc_ctype;
143/* messages */
144 struct __xlocale_st_messages *__lc_messages;
145/* monetary */
146 struct __xlocale_st_monetary *__lc_monetary;
147/* numeric */
148 struct __xlocale_st_numeric *__lc_numeric;
149/* time */
150 struct __xlocale_st_time *__lc_time;
151/* localeconv */
152 struct __xlocale_st_localeconv *__lc_localeconv;
153};
154
155#define NORMALIZE_LOCALE(x) if ((x) == NULL) { \
156 (x) = _c_locale; \
157 } else if ((x) == LC_GLOBAL_LOCALE) { \
158 (x) = &__global_locale; \
159 }
160
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)); \
164 free((x)); \
165 }
166#define XL_RETAIN(x) if ((x) && (x)->__free_extra != XPERMANENT) { OSAtomicIncrement32Barrier(&(x)->__refcount); }
167
168__private_extern__ struct __xlocale_st_runelocale _DefaultRuneXLocale;
169__private_extern__ struct _xlocale __global_locale;
170__private_extern__ pthread_key_t __locale_key;
171
172__BEGIN_DECLS
173
174void __ldpart_free_extra(struct __xlocale_st_ldpart *);
175void __xlocale_init(void);
176
177static inline __attribute__((always_inline)) locale_t
178__current_locale(void)
179{
180 locale_t __locale = (locale_t)pthread_getspecific(__locale_key);
181 return (__locale ? __locale : &__global_locale);
182}
183
184static inline __attribute__((always_inline)) locale_t
185__locale_ptr(locale_t __loc)
186{
187 return (__loc == LC_GLOBAL_LOCALE ? &__global_locale : __loc);
188}
189
190__END_DECLS
191
192#endif /* _XLOCALE_PRIVATE_H_ */