From 16bf466532d7328e971012b0731ad493b017ad29 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 6 Jun 2015 18:53:02 +0000 Subject: make static C and C.UTF-8 locales available outside of newlocale --- src/internal/locale_impl.h | 7 +++++++ src/locale/c_locale.c | 15 +++++++++++++++ src/locale/locale_map.c | 12 ++---------- src/locale/newlocale.c | 15 ++++----------- 4 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 src/locale/c_locale.c diff --git a/src/internal/locale_impl.h b/src/internal/locale_impl.h index 9b8385e9..f15e1565 100644 --- a/src/internal/locale_impl.h +++ b/src/internal/locale_impl.h @@ -12,6 +12,10 @@ struct __locale_map { const struct __locale_map *next; }; +extern const struct __locale_map __c_dot_utf8; +extern const struct __locale_struct __c_locale; +extern const struct __locale_struct __c_dot_utf8_locale; + const struct __locale_map *__get_locale(int, const char *); const char *__mo_lookup(const void *, size_t, const char *); const char *__lctrans(const char *, const struct __locale_map *); @@ -20,6 +24,9 @@ const char *__lctrans_cur(const char *); #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) #define LCTRANS_CUR(msg) __lctrans_cur(msg) +#define C_LOCALE ((locale_t)&__c_locale) +#define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) + #define CURRENT_LOCALE (__pthread_self()->locale) #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) diff --git a/src/locale/c_locale.c b/src/locale/c_locale.c new file mode 100644 index 00000000..77ccf587 --- /dev/null +++ b/src/locale/c_locale.c @@ -0,0 +1,15 @@ +#include "locale_impl.h" +#include + +static const uint32_t empty_mo[] = { 0x950412de, 0, -1, -1, -1 }; + +const struct __locale_map __c_dot_utf8 = { + .map = empty_mo, + .map_size = sizeof empty_mo, + .name = "C.UTF-8" +}; + +const struct __locale_struct __c_locale = { 0 }; +const struct __locale_struct __c_dot_utf8_locale = { + .cat[LC_CTYPE] = &__c_dot_utf8 +}; diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c index 4346bb02..c3e59174 100644 --- a/src/locale/locale_map.c +++ b/src/locale/locale_map.c @@ -24,14 +24,6 @@ static const char envvars[][12] = { "LC_MESSAGES", }; -static const uint32_t empty_mo[] = { 0x950412de, 0, -1, -1, -1 }; - -const struct __locale_map __c_dot_utf8 = { - .map = empty_mo, - .map_size = sizeof empty_mo, - .name = "C.UTF-8" -}; - const struct __locale_map *__get_locale(int cat, const char *val) { static int lock[2]; @@ -107,8 +99,8 @@ const struct __locale_map *__get_locale(int cat, const char *val) * sake of being able to do message translations at the * application level. */ if (!new && (new = malloc(sizeof *new))) { - new->map = empty_mo; - new->map_size = sizeof empty_mo; + new->map = __c_dot_utf8.map; + new->map_size = __c_dot_utf8.map_size; memcpy(new->name, val, n); new->name[n] = 0; new->next = loc_head; diff --git a/src/locale/newlocale.c b/src/locale/newlocale.c index 89d36b1d..f50bbe91 100644 --- a/src/locale/newlocale.c +++ b/src/locale/newlocale.c @@ -3,16 +3,9 @@ #include "locale_impl.h" #include "libc.h" -extern const struct __locale_map __c_dot_utf8; - -static const struct __locale_struct c_locale = { 0 }; -static const struct __locale_struct c_dot_utf8_locale = { - .cat[LC_CTYPE] = &__c_dot_utf8 -}; - int __loc_is_allocated(locale_t loc) { - return loc && loc != &c_locale && loc != &c_dot_utf8_locale; + return loc && loc != C_LOCALE && loc != UTF8_LOCALE; } locale_t __newlocale(int mask, const char *name, locale_t loc) @@ -44,9 +37,9 @@ locale_t __newlocale(int mask, const char *name, locale_t loc) } if (!j) - return (locale_t)&c_locale; - if (j==1 && tmp.cat[LC_CTYPE]==c_dot_utf8_locale.cat[LC_CTYPE]) - return (locale_t)&c_dot_utf8_locale; + return C_LOCALE; + if (j==1 && tmp.cat[LC_CTYPE]==&__c_dot_utf8) + return UTF8_LOCALE; if ((loc = malloc(sizeof *loc))) *loc = tmp; -- cgit v1.2.3-70-g09d2