1 /* $NetBSD: cmp.c,v 1.11 1997/07/20 18:53:01 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Michael Fischbein. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #include <sys/cdefs.h> 40 #ifndef lint 41 #if 0 42 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93"; 43 #else 44 __RCSID("$NetBSD: cmp.c,v 1.11 1997/07/20 18:53:01 christos Exp $"); 45 #endif 46 #endif /* not lint */ 47 48 #include <sys/types.h> 49 #include <sys/stat.h> 50 51 #include <fts.h> 52 #include <string.h> 53 54 #include "ls.h" 55 #include "extern.h" 56 57 int 58 namecmp(a, b) 59 const FTSENT *a, *b; 60 { 61 return (strcmp(a->fts_name, b->fts_name)); 62 } 63 64 int 65 revnamecmp(a, b) 66 const FTSENT *a, *b; 67 { 68 return (strcmp(b->fts_name, a->fts_name)); 69 } 70 71 int 72 modcmp(a, b) 73 const FTSENT *a, *b; 74 { 75 if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) 76 return (1); 77 else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) 78 return (-1); 79 else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) 80 return (1); 81 else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) 82 return (-1); 83 else 84 return (namecmp(a, b)); 85 } 86 87 int 88 revmodcmp(a, b) 89 const FTSENT *a, *b; 90 { 91 if (b->fts_statp->st_mtime > a->fts_statp->st_mtime) 92 return (-1); 93 else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime) 94 return (1); 95 else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec) 96 return (-1); 97 else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec) 98 return (1); 99 else 100 return (revnamecmp(a, b)); 101 } 102 103 int 104 acccmp(a, b) 105 const FTSENT *a, *b; 106 { 107 if (b->fts_statp->st_atime > a->fts_statp->st_atime) 108 return (1); 109 else if (b->fts_statp->st_atime < a->fts_statp->st_atime) 110 return (-1); 111 else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) 112 return (1); 113 else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) 114 return (-1); 115 else 116 return (namecmp(a, b)); 117 } 118 119 int 120 revacccmp(a, b) 121 const FTSENT *a, *b; 122 { 123 if (b->fts_statp->st_atime > a->fts_statp->st_atime) 124 return (-1); 125 else if (b->fts_statp->st_atime < a->fts_statp->st_atime) 126 return (1); 127 else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec) 128 return (-1); 129 else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec) 130 return (1); 131 else 132 return (revnamecmp(a, b)); 133 } 134 135 int 136 statcmp(a, b) 137 const FTSENT *a, *b; 138 { 139 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) 140 return (1); 141 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) 142 return (-1); 143 else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) 144 return (1); 145 else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) 146 return (-1); 147 else 148 return (namecmp(a, b)); 149 } 150 151 int 152 revstatcmp(a, b) 153 const FTSENT *a, *b; 154 { 155 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime) 156 return (-1); 157 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime) 158 return (1); 159 else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec) 160 return (-1); 161 else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec) 162 return (1); 163 else 164 return (revnamecmp(a, b)); 165 } 166 167 int 168 sizecmp(a, b) 169 const FTSENT *a, *b; 170 { 171 if (b->fts_statp->st_size > a->fts_statp->st_size) 172 return (1); 173 if (b->fts_statp->st_size < a->fts_statp->st_size) 174 return (-1); 175 else 176 return (namecmp(a, b)); 177 } 178 179 int 180 revsizecmp(a, b) 181 const FTSENT *a, *b; 182 { 183 if (b->fts_statp->st_size > a->fts_statp->st_size) 184 return (-1); 185 if (b->fts_statp->st_size < a->fts_statp->st_size) 186 return (1); 187 else 188 return (revnamecmp(a, b)); 189 } 190