#ifndef _XLOCALE_PRIVATE_H_
#define _XLOCALE_PRIVATE_H_
#include <sys/cdefs.h>
#define __DARWIN_XLOCALE_PRIVATE
#include <xlocale.h>
#undef __DARWIN_XLOCALE_PRIVATE
#include <stdlib.h>
#include <locale.h>
#include <libkern/OSAtomic.h>
#include <pthread.h>
#include <limits.h>
#include <os/lock.h>
#include "setlocale.h"
#include "collate.h"
#include "runetype.h"
#include "lmessages.h"
#include "lmonetary.h"
#include "lnumeric.h"
#include "timelocal.h"
#include <TargetConditionals.h>
#undef MB_CUR_MAX
#define MB_CUR_MAX (__current_locale()->__lc_ctype->__mb_cur_max)
#undef MB_CUR_MAX_L
#define MB_CUR_MAX_L(x) ((x)->__lc_ctype->__mb_cur_max)
typedef void (*__free_extra_t)(void *);
#define XPERMANENT ((__free_extra_t)-1)
#define XMAGIC 0x786c6f63616c6530LL
#define __STRUCT_COMMON \
int32_t __refcount; \
__free_extra_t __free_extra;
struct __xlocale_st_collate {
__STRUCT_COMMON
char __encoding[ENCODING_LEN + 1];
struct __collate_st_info __info;
struct __collate_st_subst *__substitute_table[COLL_WEIGHTS_MAX];
struct __collate_st_chain_pri *__chain_pri_table;
struct __collate_st_large_char_pri *__large_char_pri_table;
struct __collate_st_char_pri __char_pri_table[UCHAR_MAX + 1];
};
struct __xlocale_st_runelocale {
__STRUCT_COMMON
char __ctype_encoding[ENCODING_LEN + 1];
int __mb_cur_max;
int __mb_sb_limit;
size_t (*__mbrtowc)(wchar_t * __restrict, const char * __restrict,
size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
int (*__mbsinit)(const __darwin_mbstate_t *, struct _xlocale *);
size_t (*__mbsnrtowcs)(wchar_t * __restrict, const char ** __restrict,
size_t, size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
size_t (*__wcrtomb)(char * __restrict, wchar_t,
__darwin_mbstate_t * __restrict, struct _xlocale *);
size_t (*__wcsnrtombs)(char * __restrict, const wchar_t ** __restrict,
size_t, size_t, __darwin_mbstate_t * __restrict, struct _xlocale *);
int __datasize;
_RuneLocale _CurrentRuneLocale;
};
struct __xlocale_st_ldpart {
__STRUCT_COMMON
char *_locale_buf;
};
struct __xlocale_st_messages {
__STRUCT_COMMON
char *_messages_locale_buf;
struct lc_messages_T _messages_locale;
};
struct __xlocale_st_monetary {
__STRUCT_COMMON
char *_monetary_locale_buf;
struct lc_monetary_T _monetary_locale;
};
struct __xlocale_st_numeric {
__STRUCT_COMMON
char *_numeric_locale_buf;
struct lc_numeric_T _numeric_locale;
};
struct __xlocale_st_time {
__STRUCT_COMMON
char *_time_locale_buf;
struct lc_time_T _time_locale;
};
#define LC_NUMERIC_FP_UNINITIALIZED 0
#define LC_NUMERIC_FP_SAME_LOCALE 1
#define LC_NUMERIC_FP_USE_LOCALE 2
struct _xlocale {
__STRUCT_COMMON
__darwin_mbstate_t __mbs_mblen;
__darwin_mbstate_t __mbs_mbrlen;
__darwin_mbstate_t __mbs_mbrtowc;
__darwin_mbstate_t __mbs_mbsnrtowcs;
__darwin_mbstate_t __mbs_mbsrtowcs;
__darwin_mbstate_t __mbs_mbtowc;
__darwin_mbstate_t __mbs_wcrtomb;
__darwin_mbstate_t __mbs_wcsnrtombs;
__darwin_mbstate_t __mbs_wcsrtombs;
__darwin_mbstate_t __mbs_wctomb;
os_unfair_lock __lock;
int64_t __magic;
unsigned char __collate_load_error;
unsigned char __collate_substitute_nontrivial;
unsigned char _messages_using_locale;
unsigned char _monetary_using_locale;
unsigned char _numeric_using_locale;
unsigned char _time_using_locale;
unsigned char __mlocale_changed;
unsigned char __nlocale_changed;
unsigned char __numeric_fp_cvt;
struct __xlocale_st_collate *__lc_collate;
struct __xlocale_st_runelocale *__lc_ctype;
struct __xlocale_st_messages *__lc_messages;
struct __xlocale_st_monetary *__lc_monetary;
struct __xlocale_st_numeric *__lc_numeric;
struct _xlocale *__lc_numeric_loc;
struct __xlocale_st_time *__lc_time;
struct lconv __lc_localeconv;
};
#define DEFAULT_CURRENT_LOCALE(x) \
if ((x) == NULL) { \
(x) = __current_locale(); \
} else if ((x) == LC_GLOBAL_LOCALE) { \
(x) = &__global_locale; \
}
#define NORMALIZE_LOCALE(x) if ((x) == NULL) { \
(x) = _c_locale; \
} else if ((x) == LC_GLOBAL_LOCALE) { \
(x) = &__global_locale; \
}
#define XL_LOCK(x) os_unfair_lock_lock(&(x)->__lock);
#define XL_RELEASE(x) if ((x) && (x)->__free_extra != XPERMANENT && OSAtomicDecrement32Barrier(&(x)->__refcount) == 0) { \
if ((x)->__free_extra) \
(*(x)->__free_extra)((x)); \
free((x)); \
(x) = NULL; \
}
#define XL_RETAIN(x) if ((x) && (x)->__free_extra != XPERMANENT) { OSAtomicIncrement32Barrier(&(x)->__refcount); }
#define XL_UNLOCK(x) os_unfair_lock_unlock(&(x)->__lock);
__attribute__((visibility("hidden")))
extern struct __xlocale_st_runelocale _DefaultRuneXLocale;
__attribute__((visibility("hidden")))
extern struct _xlocale __global_locale;
__attribute__((visibility("hidden")))
extern pthread_key_t __locale_key;
__BEGIN_DECLS
void __ldpart_free_extra(struct __xlocale_st_ldpart *);
locale_t __numeric_ctype(locale_t);
void __xlocale_init(void);
static inline __attribute__((always_inline)) locale_t
__current_locale(void)
{
#if TARGET_IPHONE_SIMULATOR
if (__locale_key == (pthread_key_t)-1) {
return &__global_locale;
}
#endif
locale_t __locale = (locale_t)pthread_getspecific(__locale_key);
return (__locale ? __locale : &__global_locale);
}
static inline __attribute__((always_inline)) locale_t
__locale_ptr(locale_t __loc)
{
NORMALIZE_LOCALE(__loc);
return __loc;
}
__END_DECLS
#endif