[PATCH] ls: case-insensitive sort

gotrunks at gmail.com gotrunks at gmail.com
Sat Feb 11 12:46:04 UTC 2012


On Sat, Feb 11, 2012 at 5:11 AM, Rich Felker <dalias at aerifal.cx> wrote:
> On Sat, Feb 11, 2012 at 02:20:59AM +0100, gotrunks at gmail.com wrote:
>> Hi,
>>
>> Although coreutils `ls` sort filenames with some complexity that does
>> not fit into busybox, IMHO busybox `ls` sorting should be
>> case-insensitive to better match it.
>
> Try this on coreutils' ls:
>
> LC_COLLATE=C ls
>
> You'll find that it's case-sensitive. The behavior you're seeing is
> coming from using strcoll and a non-default locale.
>
>> diff --git a/coreutils/ls.c b/coreutils/ls.c
>> index d5b25ee..bc4692e 100644
>> --- a/coreutils/ls.c
>> +++ b/coreutils/ls.c
>> @@ -899,7 +899,7 @@ static int sortcmp(const void *a, const void *b)
>>               if (ENABLE_LOCALE_SUPPORT)
>>                       dif = strcoll(d1->name, d2->name);
>>               else
>> -                     dif = strcmp(d1->name, d2->name);
>> +                     dif = strcasecmp(d1->name, d2->name);
>
> If I'm not mistaken, this patch would change the behavior in the C
> locale, which is incorrect and non-conformant. If you want
> case-insensitive sorting, enable locale support and setup an
> appropriate locale.
>

Thanks, you are of course right. I was compiling busybox without locale support.

Regards,
-- 
Pere


More information about the busybox mailing list