diff options
Diffstat (limited to 'libc/misc/locale/locale.c')
| -rw-r--r-- | libc/misc/locale/locale.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/libc/misc/locale/locale.c b/libc/misc/locale/locale.c index 71bd77951..a2a898fdd 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) { @@ -248,12 +249,12 @@ static void update_hr_locale(const unsigned char *spec) if (loc[2] == 2) { n = stpcpy(n, utf8); } else if (loc[2] >= 3) { - n = stpcpy(n, CODESET_LIST + (int)(CODESET_LIST[loc[2] - 3])); + n = stpcpy(n, (char*) CODESET_LIST + (int)(CODESET_LIST[loc[2] - 3])); } if (at) { const char *q; *n++ = '@'; - q = LOCALE_AT_MODIFIERS; + q = (char*) LOCALE_AT_MODIFIERS; do { if (q[1] == at) { n = stpcpy(n, q+2); @@ -644,8 +645,8 @@ int attribute_hidden _locale_set_l(const unsigned char *p, __locale_t base) io = (const uint16_t *)( ((char *)__locale_mmap) + *++stp ); ii = (const uint16_t *)( ((char *)__locale_mmap) + *++stp ); d = (const unsigned char *)( ((char *)__locale_mmap) + *++stp ); - for (c=0 ; c < len ; c++) { - *(x + c) = d + ii[ r[crow + c] + io[c] ]; + for (c = 0; c < len; c++) { + x[c] = (char*)(d + ii[r[crow + c] + io[c]]); } } if (i == LC_CTYPE) { @@ -658,7 +659,7 @@ int attribute_hidden _locale_set_l(const unsigned char *p, __locale_t base) /* TODO - fix for bcc */ base->mb_cur_max = 6; } else { - assert(c==1); + assert(c == 1); base->codeset = ascii; base->encoding = __ctype_encoding_7_bit; base->mb_cur_max = 1; @@ -666,7 +667,8 @@ int attribute_hidden _locale_set_l(const unsigned char *p, __locale_t base) } else { const __codeset_8_bit_t *c8b; r = CODESET_LIST; - base->codeset = r + r[c -= 3]; + c -= 3; + base->codeset = (char *) (r + r[c]); base->encoding = __ctype_encoding_8_bit; #ifdef __UCLIBC_MJN3_ONLY__ #warning REMINDER: update 8 bit mb_cur_max when translit implemented! @@ -905,7 +907,7 @@ void attribute_hidden _locale_init_l(__locale_t base) base->tblwuplow = (const unsigned char *) &__locale_mmap->tblwuplow; base->tblwuplow_diff - = (const uint16_t *) &__locale_mmap->tblwuplow_diff; + = (const int16_t *) &__locale_mmap->tblwuplow_diff; /* base->tblwcomb */ /* = (const unsigned char *) &__locale_mmap->tblwcomb; */ /* width?? */ @@ -928,8 +930,7 @@ void attribute_hidden _locale_init_l(__locale_t base) #endif base->code2flag = __code2flag; - - _locale_set_l(C_LOCALE_SELECTOR, base); + _locale_set_l((unsigned char*) C_LOCALE_SELECTOR, base); } void _locale_init(void) attribute_hidden; @@ -1117,7 +1118,7 @@ static int find_locale(int category_mask, const char *p, /* locale name at least 5 chars long and 3rd char is '_' */ s = LOCALE_AT_MODIFIERS; do { - if (!strcmp(s+2, q+1)) { + if (!strcmp((char*) (s + 2), q + 1)) { break; } s += 2 + *s; /* TODO - fix this throughout */ @@ -1142,11 +1143,11 @@ static int find_locale(int category_mask, const char *p, /* TODO: maybe CODESET_LIST + *s ??? */ /* 7bit is 1, UTF-8 is 2, 8-bit is >= 3 */ codeset = 2; - if (strcasecmp(utf8,p+6) != 0) {/* TODO - fix! */ + if (strcasecmp(utf8, p + 6) != 0) {/* TODO - fix! */ s = CODESET_LIST; do { ++codeset; /* Increment codeset first. */ - if (!strcmp(CODESET_LIST+*s, p+6)) { + if (!strcmp((char*) CODESET_LIST + *s, p + 6)) { goto FIND_LANG_CULT; } } while (*++s); @@ -1159,7 +1160,7 @@ static int find_locale(int category_mask, const char *p, do { /* TODO -- do a binary search? */ /* TODO -- fix gen_mmap!*/ ++lang_cult; /* Increment first since C/POSIX is 0. */ - if (!strncmp(s,p,5)) { /* Found a matching locale name; */ + if (!strncmp((char*) s, p, 5)) { /* Found a matching locale name; */ goto FIND_LOCALE; } s += 5; @@ -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; } @@ -1242,7 +1244,7 @@ static unsigned char *composite_locale(int category_mask, const char *locale, __locale_t newlocale(int category_mask, const char *locale, __locale_t base) { - const unsigned char *p; + const char *p; int i, j, k; unsigned char new_selector[LOCALE_SELECTOR_SIZE]; @@ -1250,8 +1252,8 @@ __locale_t newlocale(int category_mask, const char *locale, __locale_t base) category_mask = LC_ALL_MASK; } - if (!locale || (((unsigned int)(category_mask)) > LC_ALL_MASK)) { - INVALID: + if (!locale || ((unsigned)(category_mask) > LC_ALL_MASK)) { + INVALID: __set_errno(EINVAL); return NULL; /* No locale or illegal/unsupported category. */ } @@ -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 @@ -1313,9 +1321,9 @@ __locale_t newlocale(int category_mask, const char *locale, __locale_t base) } #else if (!base) { - if ((base = malloc(sizeof(__uclibc_locale_t))) == NULL) { + base = malloc(sizeof(__uclibc_locale_t)); + if (base == NULL) return base; - } _locale_init_l(base); } |
