19ddb49cbSWarner Losh /*- 24b88c807SRodney W. Grimes * Copyright (c) 1989, 1993 34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes * 54b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes * Michael Fischbein. 74b88c807SRodney W. Grimes * 84b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes * are met: 114b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes * without specific prior written permission. 194b88c807SRodney W. Grimes * 204b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes * SUCH DAMAGE. 314b88c807SRodney W. Grimes */ 324b88c807SRodney W. Grimes 33febad2fcSSteve Price #if 0 34c73d77ceSMark Murray #ifndef lint 35febad2fcSSteve Price static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93"; 364b88c807SRodney W. Grimes #endif /* not lint */ 37c73d77ceSMark Murray #endif 385eb43ac2SDavid E. O'Brien #include <sys/cdefs.h> 395eb43ac2SDavid E. O'Brien __FBSDID("$FreeBSD$"); 405eb43ac2SDavid E. O'Brien 414b88c807SRodney W. Grimes 424b88c807SRodney W. Grimes #include <sys/types.h> 434b88c807SRodney W. Grimes #include <sys/stat.h> 444b88c807SRodney W. Grimes 454b88c807SRodney W. Grimes #include <fts.h> 464b88c807SRodney W. Grimes #include <string.h> 474b88c807SRodney W. Grimes 484b88c807SRodney W. Grimes #include "ls.h" 494b88c807SRodney W. Grimes #include "extern.h" 504b88c807SRodney W. Grimes 514b88c807SRodney W. Grimes int 5246251ddeSWarner Losh namecmp(const FTSENT *a, const FTSENT *b) 534b88c807SRodney W. Grimes { 54f137c9c1SDavid Malone 55942c84aaSAndrey A. Chernov return (strcoll(a->fts_name, b->fts_name)); 564b88c807SRodney W. Grimes } 574b88c807SRodney W. Grimes 584b88c807SRodney W. Grimes int 5946251ddeSWarner Losh revnamecmp(const FTSENT *a, const FTSENT *b) 604b88c807SRodney W. Grimes { 61f137c9c1SDavid Malone 62942c84aaSAndrey A. Chernov return (strcoll(b->fts_name, a->fts_name)); 634b88c807SRodney W. Grimes } 644b88c807SRodney W. Grimes 654b88c807SRodney W. Grimes int 6646251ddeSWarner Losh modcmp(const FTSENT *a, const FTSENT *b) 674b88c807SRodney W. Grimes { 68f137c9c1SDavid Malone 6960e52383SDavid Malone if (b->fts_statp->st_mtimespec.tv_sec > 7060e52383SDavid Malone a->fts_statp->st_mtimespec.tv_sec) 71f137c9c1SDavid Malone return (1); 7260e52383SDavid Malone if (b->fts_statp->st_mtimespec.tv_sec < 7360e52383SDavid Malone a->fts_statp->st_mtimespec.tv_sec) 74f137c9c1SDavid Malone return (-1); 7560e52383SDavid Malone if (b->fts_statp->st_mtimespec.tv_nsec > 7660e52383SDavid Malone a->fts_statp->st_mtimespec.tv_nsec) 77f137c9c1SDavid Malone return (1); 7860e52383SDavid Malone if (b->fts_statp->st_mtimespec.tv_nsec < 7960e52383SDavid Malone a->fts_statp->st_mtimespec.tv_nsec) 80f137c9c1SDavid Malone return (-1); 8160e52383SDavid Malone return (strcoll(a->fts_name, b->fts_name)); 824b88c807SRodney W. Grimes } 834b88c807SRodney W. Grimes 844b88c807SRodney W. Grimes int 8546251ddeSWarner Losh revmodcmp(const FTSENT *a, const FTSENT *b) 864b88c807SRodney W. Grimes { 87f137c9c1SDavid Malone 8860e52383SDavid Malone return (modcmp(b, a)); 894b88c807SRodney W. Grimes } 904b88c807SRodney W. Grimes 914b88c807SRodney W. Grimes int 9246251ddeSWarner Losh acccmp(const FTSENT *a, const FTSENT *b) 934b88c807SRodney W. Grimes { 94f137c9c1SDavid Malone 9560e52383SDavid Malone if (b->fts_statp->st_atimespec.tv_sec > 9660e52383SDavid Malone a->fts_statp->st_atimespec.tv_sec) 97f137c9c1SDavid Malone return (1); 9860e52383SDavid Malone if (b->fts_statp->st_atimespec.tv_sec < 9960e52383SDavid Malone a->fts_statp->st_atimespec.tv_sec) 100f137c9c1SDavid Malone return (-1); 10160e52383SDavid Malone if (b->fts_statp->st_atimespec.tv_nsec > 10260e52383SDavid Malone a->fts_statp->st_atimespec.tv_nsec) 103f137c9c1SDavid Malone return (1); 10460e52383SDavid Malone if (b->fts_statp->st_atimespec.tv_nsec < 10560e52383SDavid Malone a->fts_statp->st_atimespec.tv_nsec) 106f137c9c1SDavid Malone return (-1); 10760e52383SDavid Malone return (strcoll(a->fts_name, b->fts_name)); 1084b88c807SRodney W. Grimes } 1094b88c807SRodney W. Grimes 1104b88c807SRodney W. Grimes int 11146251ddeSWarner Losh revacccmp(const FTSENT *a, const FTSENT *b) 1124b88c807SRodney W. Grimes { 113f137c9c1SDavid Malone 11460e52383SDavid Malone return (acccmp(b, a)); 1154b88c807SRodney W. Grimes } 1164b88c807SRodney W. Grimes 1174b88c807SRodney W. Grimes int 11846251ddeSWarner Losh statcmp(const FTSENT *a, const FTSENT *b) 1194b88c807SRodney W. Grimes { 120f137c9c1SDavid Malone 12160e52383SDavid Malone if (b->fts_statp->st_ctimespec.tv_sec > 12260e52383SDavid Malone a->fts_statp->st_ctimespec.tv_sec) 123f137c9c1SDavid Malone return (1); 12460e52383SDavid Malone if (b->fts_statp->st_ctimespec.tv_sec < 12560e52383SDavid Malone a->fts_statp->st_ctimespec.tv_sec) 126f137c9c1SDavid Malone return (-1); 12760e52383SDavid Malone if (b->fts_statp->st_ctimespec.tv_nsec > 12860e52383SDavid Malone a->fts_statp->st_ctimespec.tv_nsec) 129f137c9c1SDavid Malone return (1); 13060e52383SDavid Malone if (b->fts_statp->st_ctimespec.tv_nsec < 13160e52383SDavid Malone a->fts_statp->st_ctimespec.tv_nsec) 132f137c9c1SDavid Malone return (-1); 13360e52383SDavid Malone return (strcoll(a->fts_name, b->fts_name)); 1344b88c807SRodney W. Grimes } 1354b88c807SRodney W. Grimes 1364b88c807SRodney W. Grimes int 13746251ddeSWarner Losh revstatcmp(const FTSENT *a, const FTSENT *b) 1384b88c807SRodney W. Grimes { 139f137c9c1SDavid Malone 14060e52383SDavid Malone return (statcmp(b, a)); 1414b88c807SRodney W. Grimes } 142