summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-06-13 00:13:42 (GMT)
committer Denys Vlasenko <vda.linux@googlemail.com>2011-06-13 00:13:42 (GMT)
commitf194cc1f3376a26158940d91d0179a3e70233e10 (patch)
tree3bf78d8f6b64588fdbeb7dc83d337caa776f957a
parentb307eabf4d47cbe224e35711838c8545f610205b (diff)
downloadbusybox-f194cc1f3376a26158940d91d0179a3e70233e10.tar.gz
busybox-f194cc1f3376a26158940d91d0179a3e70233e10.tar.bz2
ls: make -v and -X actually work as intended
function old new delta strverscmp - 236 +236 sortcmp 186 254 +68 static.result_type - 60 +60 static.next_state 12 16 +4 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/ls.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/coreutils/ls.c b/coreutils/ls.c
index dec0f85..ee73473 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -874,19 +874,27 @@ static int sortcmp(const void *a, const void *b)
// instead of branch forest
if (sort_opts == SORT_SIZE) {
dif = (d2->dn_size - d1->dn_size);
- } else if (sort_opts == SORT_ATIME) {
+ } else
+ if (sort_opts == SORT_ATIME) {
dif = (d2->dn_atime - d1->dn_atime);
- } else if (sort_opts == SORT_CTIME) {
+ } else
+ if (sort_opts == SORT_CTIME) {
dif = (d2->dn_ctime - d1->dn_ctime);
- } else if (sort_opts == SORT_MTIME) {
+ } else
+ if (sort_opts == SORT_MTIME) {
dif = (d2->dn_mtime - d1->dn_mtime);
- } else if (sort_opts == SORT_DIR) {
+ } else
+ if (sort_opts == SORT_DIR) {
dif = S_ISDIR(d2->dn_mode) - S_ISDIR(d1->dn_mode);
- /* } else if (sort_opts == SORT_VERSION) { */
- /* } else if (sort_opts == SORT_EXT) { */
+ } else
+ if (sort_opts == SORT_VERSION) {
+ dif = strverscmp(d1->name, d2->name);
+ } else
+ if (sort_opts == SORT_EXT) {
+ dif = strcmp(strchrnul(d1->name, '.'), strchrnul(d2->name, '.'));
}
if (dif == 0) {
- /* sort by name, or tie_breaker for other sorts */
+ /* sort by name, use as tie breaker for other sorts */
if (ENABLE_LOCALE_SUPPORT)
dif = strcoll(d1->name, d2->name);
else