Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/libbb/unicode.c


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/libbb/unicode.c

    r3232 r3621  
    2929    size_t width;
    3030
     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     */
    3142//TODO: avoid repeated calls by caching last string?
    32     setlocale(LC_ALL, (LANG && LANG[0]) ? LANG : "C");
     43    setlocale(LC_CTYPE, LANG ? LANG : "");
    3344
    3445    /* 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);
    3747    unicode_status = (width == 1 ? UNICODE_ON : UNICODE_OFF);
    3848}
     
    4050void FAST_FUNC init_unicode(void)
    4151{
    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    }
    4462}
    4563
     
    5977void FAST_FUNC init_unicode(void)
    6078{
    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    }
    6385}
    6486# endif
     
    964986/* The rest is mostly same for libc and for "homegrown" support */
    965987
    966 #if 0 // UNUSED
    967988size_t FAST_FUNC unicode_strlen(const char *string)
    968989{
     
    972993    return width;
    973994}
    974 #endif
    975995
    976996size_t FAST_FUNC unicode_strwidth(const char *string)
Note: See TracChangeset for help on using the changeset viewer.