diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 22:36:09 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-01-03 22:36:09 +0000 |
commit | a07e8cc3030f8743a5d3b39bd97994fb54aa76fb (patch) | |
tree | 54bf075e78894ab030dfe86c8d7537e602d04e44 /bin/ls/cmp.c | |
parent | b3e85814e581c12d86755a6215992e1cbb47a912 (diff) |
From NetBSD:
- Correct sorting behaviour.
- Do multicolumn output in a way that's a more likely to line up evenly.
From D'Arcy J.M. Cain <darcy@druid.com>, NetBSD PR #2965.
Diffstat (limited to 'bin/ls/cmp.c')
-rw-r--r-- | bin/ls/cmp.c | 90 |
1 files changed, 73 insertions, 17 deletions
diff --git a/bin/ls/cmp.c b/bin/ls/cmp.c index 3ac4f52ad3c..2b62e7ecc4a 100644 --- a/bin/ls/cmp.c +++ b/bin/ls/cmp.c @@ -1,5 +1,5 @@ -/* $OpenBSD: cmp.c,v 1.2 1996/06/23 14:20:18 deraadt Exp $ */ -/* $NetBSD: cmp.c,v 1.8 1995/03/21 09:06:20 cgd Exp $ */ +/* $OpenBSD: cmp.c,v 1.3 1997/01/03 22:36:07 millert Exp $ */ +/* $NetBSD: cmp.c,v 1.10 1996/07/08 10:32:01 mycroft Exp $ */ /* * Copyright (c) 1989, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: cmp.c,v 1.2 1996/06/23 14:20:18 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: cmp.c,v 1.3 1997/01/03 22:36:07 millert Exp $"; #endif #endif /* not lint */ @@ -72,42 +72,96 @@ int modcmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_mtime - a->fts_statp->st_mtime); + if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) + return (1); + else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) + return (-1); + else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) + return (1); + else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) + return (-1); + else + return (namecmp(a, b)); } int revmodcmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_mtime - b->fts_statp->st_mtime); + if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) + return (-1); + else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) + return (1); + else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) + return (-1); + else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) + return (1); + else + return (revnamecmp(a, b)); } int acccmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_atime - a->fts_statp->st_atime); + if (b->fts_statp->st_atime > a->fts_statp->st_atime) + return (1); + else if (b->fts_statp->st_atime < a->fts_statp->st_atime) + return (-1); + else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) + return (1); + else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) + return (-1); + else + return (namecmp(a, b)); } int revacccmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_atime - b->fts_statp->st_atime); + if (b->fts_statp->st_atime > a->fts_statp->st_atime) + return (-1); + else if (b->fts_statp->st_atime < a->fts_statp->st_atime) + return (1); + else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) + return (-1); + else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) + return (1); + else + return (revnamecmp(a, b)); } int statcmp(a, b) const FTSENT *a, *b; { - return (b->fts_statp->st_ctime - a->fts_statp->st_ctime); + if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) + return (1); + else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) + return (-1); + else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) + return (1); + else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) + return (-1); + else + return (namecmp(a, b)); } int revstatcmp(a, b) const FTSENT *a, *b; { - return (a->fts_statp->st_ctime - b->fts_statp->st_ctime); + if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) + return (-1); + else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) + return (1); + else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) + return (-1); + else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) + return (1); + else + return (revnamecmp(a, b)); } int @@ -115,19 +169,21 @@ sizecmp(a, b) const FTSENT *a, *b; { if (b->fts_statp->st_size > a->fts_statp->st_size) - return 1; + return (1); if (b->fts_statp->st_size < a->fts_statp->st_size) - return -1; - return 0; + return (-1); + else + return (namecmp(a, b)); } int revsizecmp(a, b) const FTSENT *a, *b; { - if (a->fts_statp->st_size > b->fts_statp->st_size) - return 1; - if (a->fts_statp->st_size < b->fts_statp->st_size) - return -1; - return 0; + 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); + else + return (revnamecmp(a, b)); } |