How do I (unconditionally) enable unicode support in busybox?

Denys Vlasenko vda.linux at googlemail.com
Mon Aug 11 18:02:40 UTC 2014


On Mon, Aug 4, 2014 at 7:50 AM, James Bowlin <bitjam at gmail.com> wrote:
> I run busybox in an initrd (initramfs) environment using both
> legacy Grub and isolinux as boot loaders.  I want to be able to
> get the correct length of unicode strings in characters, not
> bytes.  I always have these two options set:
>
>     CONFIG_UNICODE_SUPPORT=y
>     CONFIG_UNICODE_WIDE_WCHARS=y

Correct. Without CONFIG_UNICODE_SUPPORT=y,
busybox would simply pretend that every byte
is one character.

> and I've played with the 3 combinations of:
>
>     CONFIG_UNICODE_USING_LOCALE
>     CONFIG_FEATURE_CHECK_UNICODE_IN_ENV
>
> both off, and one or the other on.

I tried to supply help texts for these options.
Please let me know if they are not clear enough:

config UNICODE_USING_LOCALE
        bool "Use libc routines for Unicode (else uses internal ones)"
        default n
        depends on UNICODE_SUPPORT && LOCALE_SUPPORT
        help
          With this option on, Unicode support is implemented using libc
          routines. Otherwise, internal implementation is used.
          Internal implementation is smaller.

config FEATURE_CHECK_UNICODE_IN_ENV
        bool "Check $LC_ALL, $LC_CTYPE and $LANG environment variables"
        default n
        depends on UNICODE_SUPPORT && !UNICODE_USING_LOCALE
        help
          With this option on, Unicode support is activated
          only if locale-related variables have the value of the form
          "xxxx.utf8"

          Otherwise, Unicode support will be always enabled and active.


How it is intended to work:
If you are building busybox against libc with locale support,
you can select CONFIG_UNICODE_USING_LOCALE=y.
In this case, Unicode-ness will be determined by libc -
busybox just calls setlocale():

        /* Set locale for everybody except 'init' */
        if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
                setlocale(LC_ALL, "");

and thus, it's up to libc code in setlocale() to set up things.
(Note: in this case, busybox code has no control whether $LANG
has some effect or not: it depends on *libc*. For glibc,
$LANG will control Unicode; for some other libc, it may not).

If your libc has no locale support, you can't use
CONFIG_UNICODE_USING_LOCALE=y.

You also can decide to not use it even though libc supports it
(say, because libc locale code is big). If it is unset, an internal
implementation will be in use.

In this case, FEATURE_CHECK_UNICODE_IN_ENV controls
whether Unicode is "always on" or it depends on $LANG.

Looks like you want to set CONFIG_UNICODE_SUPPORT=y
and unset both of these latter options.
This way, all busybox applets should always work
in Unicode mode.

Please let me know if that setup does not work for you.


More information about the busybox mailing list