Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/unicode.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/libbb/unicode.c
r3232 r3621 29 29 size_t width; 30 30 31 /* We pass "" instead of "C" because some libc's have 32 * non-ASCII default locale for setlocale("") call 33 * (this allows users of such libc to have Unicoded 34 * system without having to mess with env). 35 * 36 * We set LC_CTYPE because (a) we may be called with $LC_CTYPE 37 * value in LANG, not with $LC_ALL, (b) internationalized 38 * LC_NUMERIC and LC_TIME are more PITA than benefit 39 * (for one, some utilities have hard time with comma 40 * used as a fractional separator). 41 */ 31 42 //TODO: avoid repeated calls by caching last string? 32 setlocale(LC_ ALL, (LANG && LANG[0]) ? LANG : "C");43 setlocale(LC_CTYPE, LANG ? LANG : ""); 33 44 34 45 /* In unicode, this is a one character string */ 35 // can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused 36 width = mbstowcs(NULL, unicode_0x394, INT_MAX); 46 width = unicode_strlen(unicode_0x394); 37 47 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); 38 48 } … … 40 50 void FAST_FUNC init_unicode(void) 41 51 { 42 if (unicode_status == UNICODE_UNKNOWN) 43 reinit_unicode(getenv("LANG")); 52 /* Some people set only $LC_CTYPE, not $LC_ALL, because they want 53 * only Unicode to be activated on their system, not the whole 54 * shebang of wrong decimal points, strange date formats and so on. 55 */ 56 if (unicode_status == UNICODE_UNKNOWN) { 57 char *s = getenv("LC_ALL"); 58 if (!s) s = getenv("LC_CTYPE"); 59 if (!s) s = getenv("LANG"); 60 reinit_unicode(s); 61 } 44 62 } 45 63 … … 59 77 void FAST_FUNC init_unicode(void) 60 78 { 61 if (unicode_status == UNICODE_UNKNOWN) 62 reinit_unicode(getenv("LANG")); 79 if (unicode_status == UNICODE_UNKNOWN) { 80 char *s = getenv("LC_ALL"); 81 if (!s) s = getenv("LC_CTYPE"); 82 if (!s) s = getenv("LANG"); 83 reinit_unicode(s); 84 } 63 85 } 64 86 # endif … … 964 986 /* The rest is mostly same for libc and for "homegrown" support */ 965 987 966 #if 0 // UNUSED967 988 size_t FAST_FUNC unicode_strlen(const char *string) 968 989 { … … 972 993 return width; 973 994 } 974 #endif975 995 976 996 size_t FAST_FUNC unicode_strwidth(const char *string)
Note:
See TracChangeset
for help on using the changeset viewer.