[Toybox] [PATCH] Fix ls sorting by name.

enh enh at google.com
Sat Aug 15 15:46:13 PDT 2015


Fix ls sorting by name.

POSIX says ls sorts according to the collating sequence in the current
locale. In the en-US.UTF-8 locale, coreutils ls sorts "Config.in" and
"configure" before "LICENSE"; without this patch toybox ls sorts
capitals first.

diff --git a/toys/posix/ls.c b/toys/posix/ls.c
index f951198..ca4e172 100644
--- a/toys/posix/ls.c
+++ b/toys/posix/ls.c
@@ -163,7 +163,7 @@ static int compare(void *a, void *b)
     if (dta->st.st_mtime > dtb->st.st_mtime) ret = -1;
     else if (dta->st.st_mtime < dtb->st.st_mtime) ret = 1;
   }
-  if (!ret) ret = strcmp(dta->name, dtb->name);
+  if (!ret) ret = strcoll(dta->name, dtb->name);
   return ret * reverse;
 }


More information about the Toybox mailing list