summaryrefslogtreecommitdiffstats
path: root/bin/ls/cmp.c
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2005-06-03 11:05:58 +0000
committerdd <dd@FreeBSD.org>2005-06-03 11:05:58 +0000
commit99a2093aa5adcd2cfd2e9f9985142318d188b080 (patch)
tree9bcf1fb5bb7f5fa54b12f829708d0a6ab8840ca2 /bin/ls/cmp.c
parent899df482c7480cb865309c0da379b01d4546521d (diff)
downloadFreeBSD-src-99a2093aa5adcd2cfd2e9f9985142318d188b080.zip
FreeBSD-src-99a2093aa5adcd2cfd2e9f9985142318d188b080.tar.gz
Add the -S option to sort files by size. NetBSD and OpenBSD already
have this option with identical semantics (sorting large files first). -r can be used to reverse the sort if that is desired. PR: 81625 Submitted by: Kostas Blekos <mplekos@physics.upatras.gr>, keramida
Diffstat (limited to 'bin/ls/cmp.c')
-rw-r--r--bin/ls/cmp.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c
index 903da8b..37b4a75 100644
--- a/bin/ls/cmp.c
+++ b/bin/ls/cmp.c
@@ -139,3 +139,21 @@ revstatcmp(const FTSENT *a, const FTSENT *b)
return (statcmp(b, a));
}
+
+int
+sizecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ if (b->fts_statp->st_size > a->fts_statp->st_size)
+ return (1);
+ if (b->fts_statp->st_size < a->fts_statp->st_size)
+ return (-1);
+ return (strcoll(a->fts_name, b->fts_name));
+}
+
+int
+revsizecmp(const FTSENT *a, const FTSENT *b)
+{
+
+ return (sizecmp(b, a));
+}
OpenPOWER on IntegriCloud