summaryrefslogtreecommitdiff
path: root/libbb/unicode.c
diff options
context:
space:
mode:
authorDenys Vlasenko2011-03-23 17:59:27 +0100
committerDenys Vlasenko2011-03-23 17:59:27 +0100
commit20704f066250744c0c2b84920c27d0fd0aa9e935 (patch)
tree8a76e56e4be0beb84dbe993922d4be86ab694350 /libbb/unicode.c
parent7f4b769c42f3773ff2e2e749547291dcb7e85d01 (diff)
downloadbusybox-20704f066250744c0c2b84920c27d0fd0aa9e935.zip
busybox-20704f066250744c0c2b84920c27d0fd0aa9e935.tar.gz
ash,hush: recheck LANG before every line input
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/unicode.c')
-rw-r--r--libbb/unicode.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/libbb/unicode.c b/libbb/unicode.c
index 08a4c74..d01efd9 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -23,37 +23,43 @@ uint8_t unicode_status;
/* Unicode support using libc locale support. */
-void FAST_FUNC init_unicode(void)
+void FAST_FUNC reinit_unicode(const char *LANG UNUSED_PARAM)
{
static const char unicode_0x394[] = { 0xce, 0x94, 0 };
size_t width;
- if (unicode_status != UNICODE_UNKNOWN)
- return;
+//TODO: call setlocale(LC_ALL, LANG) here?
+
/* In unicode, this is a one character string */
// can use unicode_strlen(string) too, but otherwise unicode_strlen() is unused
width = mbstowcs(NULL, unicode_0x394, INT_MAX);
unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
}
+void FAST_FUNC init_unicode(void)
+{
+ if (unicode_status == UNICODE_UNKNOWN)
+ reinit_unicode(NULL /*getenv("LANG")*/);
+}
+
#else
/* Homegrown Unicode support. It knows only C and Unicode locales. */
# if ENABLE_FEATURE_CHECK_UNICODE_IN_ENV
-void FAST_FUNC init_unicode(void)
+void FAST_FUNC reinit_unicode(const char *LANG)
{
- char *lang;
-
- if (unicode_status != UNICODE_UNKNOWN)
- return;
-
unicode_status = UNICODE_OFF;
- lang = getenv("LANG");
- if (!lang || !(strstr(lang, ".utf") || strstr(lang, ".UTF")))
+ if (!LANG || !(strstr(LANG, ".utf") || strstr(LANG, ".UTF")))
return;
unicode_status = UNICODE_ON;
}
+
+void FAST_FUNC init_unicode(void)
+{
+ if (unicode_status == UNICODE_UNKNOWN)
+ reinit_unicode(getenv("LANG"));
+}
# endif
static size_t wcrtomb_internal(char *s, wchar_t wc)