OLD | NEW |
1 #include <stdlib.h> | 1 #include <stdlib.h> |
2 #include <string.h> | 2 #include <string.h> |
3 #include "locale_impl.h" | 3 #include "locale_impl.h" |
4 #include "libc.h" | 4 #include "libc.h" |
5 | 5 |
6 int __loc_is_allocated(locale_t loc) | 6 int __loc_is_allocated(locale_t loc) { |
7 { | 7 return loc && loc != C_LOCALE && loc != UTF8_LOCALE; |
8 » return loc && loc != C_LOCALE && loc != UTF8_LOCALE; | |
9 } | 8 } |
10 | 9 |
11 locale_t __newlocale(int mask, const char *name, locale_t loc) | 10 locale_t __newlocale(int mask, const char* name, locale_t loc) { |
12 { | 11 int i, j; |
13 » int i, j; | 12 struct __locale_struct tmp; |
14 » struct __locale_struct tmp; | 13 const struct __locale_map* lm; |
15 » const struct __locale_map *lm; | |
16 | 14 |
17 » /* For locales with allocated storage, modify in-place. */ | 15 /* For locales with allocated storage, modify in-place. */ |
18 » if (__loc_is_allocated(loc)) { | 16 if (__loc_is_allocated(loc)) { |
19 » » for (i=0; i<LC_ALL; i++) | 17 for (i = 0; i < LC_ALL; i++) |
20 » » » if (mask & (1<<i)) | 18 if (mask & (1 << i)) |
21 » » » » loc->cat[i] = __get_locale(i, name); | 19 loc->cat[i] = __get_locale(i, name); |
22 » » return loc; | 20 return loc; |
23 » } | 21 } |
24 | 22 |
25 » /* Otherwise, build a temporary locale object, which will only | 23 /* Otherwise, build a temporary locale object, which will only |
26 » * be instantiated in allocated storage if it does not match | 24 * be instantiated in allocated storage if it does not match |
27 » * one of the built-in static locales. This makes the common | 25 * one of the built-in static locales. This makes the common |
28 » * usage case for newlocale, getting a C locale with predictable | 26 * usage case for newlocale, getting a C locale with predictable |
29 » * behavior, very fast, and more importantly, fail-safe. */ | 27 * behavior, very fast, and more importantly, fail-safe. */ |
30 » for (j=i=0; i<LC_ALL; i++) { | 28 for (j = i = 0; i < LC_ALL; i++) { |
31 » » if (loc && !(mask & (1<<i))) | 29 if (loc && !(mask & (1 << i))) |
32 » » » lm = loc->cat[i]; | 30 lm = loc->cat[i]; |
33 » » else | 31 else |
34 » » » lm = __get_locale(i, mask & (1<<i) ? name : ""); | 32 lm = __get_locale(i, mask & (1 << i) ? name : ""); |
35 » » if (lm) j++; | 33 if (lm) |
36 » » tmp.cat[i] = lm; | 34 j++; |
37 » } | 35 tmp.cat[i] = lm; |
| 36 } |
38 | 37 |
39 » if (!j) | 38 if (!j) |
40 » » return C_LOCALE; | 39 return C_LOCALE; |
41 » if (j==1 && tmp.cat[LC_CTYPE]==&__c_dot_utf8) | 40 if (j == 1 && tmp.cat[LC_CTYPE] == &__c_dot_utf8) |
42 » » return UTF8_LOCALE; | 41 return UTF8_LOCALE; |
43 | 42 |
44 » if ((loc = malloc(sizeof *loc))) *loc = tmp; | 43 if ((loc = malloc(sizeof *loc))) |
| 44 *loc = tmp; |
45 | 45 |
46 » return loc; | 46 return loc; |
47 } | 47 } |
48 | 48 |
49 weak_alias(__newlocale, newlocale); | 49 weak_alias(__newlocale, newlocale); |
OLD | NEW |