aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/unicode.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 08a4c7427..d01efd9a2 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -23,37 +23,43 @@ uint8_t unicode_status;
23 23
24/* Unicode support using libc locale support. */ 24/* Unicode support using libc locale support. */
25 25
26void FAST_FUNC init_unicode(void) 26void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM)
27{ 27{
28 static const char unicode_0x394[] = { 0xce, 0x94, 0 }; 28 static const char unicode_0x394[] = { 0xce, 0x94, 0 };
29 size_t width; 29 size_t width;
30 30
31 if (unicode_status != UNICODE_UNKNOWN) 31//TODO: call setlocale(LC_ALL, LANG) here?
32 return; 32
33 /* In unicode, this is a one character string */ 33 /* In unicode, this is a one character string */
34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused 34// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused
35 width = mbstowcs(NULL, unicode_0x394, INT_MAX); 35 width = mbstowcs(NULL, unicode_0x394, INT_MAX);
36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF); 36 unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
37} 37}
38 38
39void FAST_FUNC init_unicode(void)
40{
41 if (unicode_status == UNICODE_UNKNOWN)
42 reinit_unicode(NULL /*getenv("LANG")*/);
43}
44
39#else 45#else
40 46
41/* Homegrown Unicode support. It knows only C and Unicode locales. */ 47/* Homegrown Unicode support. It knows only C and Unicode locales. */
42 48
43# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV 49# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
44void FAST_FUNC init_unicode(void) 50void FAST_FUNC reinit_unicode(const char *LANG)
45{ 51{
46 char *lang;
47
48 if (unicode_status != UNICODE_UNKNOWN)
49 return;
50
51 unicode_status = UNICODE_OFF; 52 unicode_status = UNICODE_OFF;
52 lang = getenv("LANG"); 53 if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF")))
53 if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF")))
54 return; 54 return;
55 unicode_status = UNICODE_ON; 55 unicode_status = UNICODE_ON;
56} 56}
57
58void FAST_FUNC init_unicode(void)
59{
60 if (unicode_status == UNICODE_UNKNOWN)
61 reinit_unicode(getenv("LANG"));
62}
57# endif 63# endif
58 64
59static size_t wcrtomb_internal(char *s, wchar_t wc) 65static size_t wcrtomb_internal(char *s, wchar_t wc)