summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extra/locale/locale_mmap.h4
-rw-r--r--libc/misc/locale/locale.c30
2 files changed, 21 insertions, 13 deletions
diff --git a/extra/locale/locale_mmap.h b/extra/locale/locale_mmap.h
index 1b748239b..e9dcbc537 100644
--- a/extra/locale/locale_mmap.h
+++ b/extra/locale/locale_mmap.h
@@ -35,7 +35,7 @@ typedef struct {
#ifdef __CTYPE_HAS_8_BIT_LOCALES
const unsigned char tbl8ctype[__LOCALE_DATA_Cctype_TBL_LEN];
- const unsigned char tbl8uplow[__LOCALE_DATA_Cuplow_TBL_LEN];
+ const unsigned char tbl8uplow[__LOCALE_DATA_Cuplow_TBL_LEN];
#ifdef __WCHAR_ENABLED
const uint16_t tbl8c2wc[__LOCALE_DATA_Cc2wc_TBL_LEN]; /* char > 0x7f to wide char */
const unsigned char tbl8wc2c[__LOCALE_DATA_Cwc2c_TBL_LEN];
@@ -72,7 +72,7 @@ typedef struct {
const uint16_t collate_data[__lc_collate_data_LEN];
unsigned char lc_common_item_offsets_LEN[__LOCALE_DATA_CATEGORIES];
- size_t lc_common_tbl_offsets[__LOCALE_DATA_CATEGORIES * 4];
+ size_t lc_common_tbl_offsets[__LOCALE_DATA_CATEGORIES * 4];
/* offsets from start of locale_mmap_t */
/* rows, item_offsets, item_idx, data */
diff --git a/libc/misc/locale/locale.c b/libc/misc/locale/locale.c
index 71bd77951..29a80fab0 100644
--- a/libc/misc/locale/locale.c
+++ b/libc/misc/locale/locale.c
@@ -230,7 +230,8 @@ static void update_hr_locale(const unsigned char *spec)
+ __LOCALE_DATA_WIDTH_LOCALES * ((((int)(*s & 0x7f)) << 7)
+ (s[1] & 0x7f));
if (category == LC_ALL) {
- n = stpcpy(n, CATEGORY_NAMES + (int) CATEGORY_NAMES[i]);
+ /* CATEGORY_NAMES is unsigned char* */
+ n = stpcpy(n, (char*) CATEGORY_NAMES + (int) CATEGORY_NAMES[i]);
*n++ = '=';
}
if (*loc == 0) {
@@ -1217,7 +1218,8 @@ static unsigned char *composite_locale(int category_mask, const char *locale,
t = strtok_r(buf, "=", &e); /* This can't fail because of strchr test above. */
do {
c = 0;
- while (strcmp(CATEGORY_NAMES + (int) CATEGORY_NAMES[c], t)) {
+ /* CATEGORY_NAMES is unsigned char* */
+ while (strcmp((char*) CATEGORY_NAMES + (int) CATEGORY_NAMES[c], t)) {
if (++c == LC_ALL) { /* Unknown category name! */
return NULL;
}
@@ -1262,11 +1264,13 @@ __locale_t newlocale(int category_mask, const char *locale, __locale_t base)
strcpy((char *) new_selector,
(base ? (char *) base->cur_locale : C_LOCALE_SELECTOR));
- if (!*locale) { /* locale == "", so check environment. */
-#ifndef __UCLIBC_HAS_THREADS__
- static /* If no threads, then envstr can be static. */
-#endif /* __UCLIBC_HAS_THREADS__ */
- const char *envstr[4] = { "LC_ALL", NULL, "LANG", posix };
+ if (!locale[0]) { /* locale == "", so check environment. */
+ const char *envstr[4];
+
+ envstr[0] = "LC_ALL";
+ envstr[1] = NULL;
+ envstr[2] = "LANG";
+ envstr[3] = posix;
i = 1;
k = 0;
@@ -1275,12 +1279,16 @@ __locale_t newlocale(int category_mask, const char *locale, __locale_t base)
/* Note: SUSv3 doesn't define a fallback mechanism here.
* So, if LC_ALL is invalid, we do _not_ continue trying
* the other environment vars. */
- envstr[1] = CATEGORY_NAMES + CATEGORY_NAMES[k];
+ envstr[1] = (char*) CATEGORY_NAMES + CATEGORY_NAMES[k];
j = 0;
- do {
+ while (1) {
p = envstr[j];
- } while ((++j < 4) && (!(p = getenv(p)) || !*p));
-
+ if (++j >= 4)
+ break; /* now p == "POSIX" */
+ p = getenv(p);
+ if (p && p[0])
+ break;
+ };
/* The user set something... is it valid? */
/* Note: Since we don't support user-supplied locales and