提交 16bf4665 编写于 作者: R Rich Felker

make static C and C.UTF-8 locales available outside of newlocale

上级 312eea2e
......@@ -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])
......
#include "locale_impl.h"
#include <stdint.h>
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
};
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册