summaryrefslogtreecommitdiffstats
path: root/bin/ls/cmp.c
diff options
context:
space:
mode:
authorgrog <grog@FreeBSD.org>2012-11-08 00:24:26 +0000
committergrog <grog@FreeBSD.org>2012-11-08 00:24:26 +0000
commit9c0bd42e1e1976aa2b56165c1e4e3c5d629e26d2 (patch)
tree809ae8503592a5b42218a8eca79c666412379d4e /bin/ls/cmp.c
parentab66165b630d8183f6fa1931e22b555b45d03316 (diff)
downloadFreeBSD-src-9c0bd42e1e1976aa2b56165c1e4e3c5d629e26d2.zip
FreeBSD-src-9c0bd42e1e1976aa2b56165c1e4e3c5d629e26d2.tar.gz
Add y flag and environment variable LS_SAMESORT to specify the same
sorting order for time and name with the -t option. IEEE Std 1003.2 (POSIX.2) mandates that the -t option sort in descending order, and that if two files have the same timestamp, they should be sorted in ascending order of their names. The -r flag reverses both of these sort orders, so they're never the same. This creates significant problems for sequentially named files stored on FAT file systems, where it can be impossible to list them in the order in which they were created. Add , (comma) option to print file sizes grouped and separated by thousands using the non-monetary separator returned by localeconv(3), typically a comma or period. MFC after: 14 days
Diffstat (limited to 'bin/ls/cmp.c')
-rw-r--r--bin/ls/cmp.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c
index 84fb038..8729666 100644
--- a/bin/ls/cmp.c
+++ b/bin/ls/cmp.c
@@ -78,7 +78,10 @@ modcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_mtim.tv_nsec <
a->fts_statp->st_mtim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+ if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+ else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -104,7 +107,10 @@ acccmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_atim.tv_nsec <
a->fts_statp->st_atim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+ if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+ else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -130,7 +136,10 @@ birthcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_birthtim.tv_nsec <
a->fts_statp->st_birthtim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+ if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+ else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
@@ -156,7 +165,10 @@ statcmp(const FTSENT *a, const FTSENT *b)
if (b->fts_statp->st_ctim.tv_nsec <
a->fts_statp->st_ctim.tv_nsec)
return (-1);
- return (strcoll(a->fts_name, b->fts_name));
+ if (f_samesort)
+ return (strcoll(b->fts_name, a->fts_name));
+ else
+ return (strcoll(a->fts_name, b->fts_name));
}
int
OpenPOWER on IntegriCloud