cmp.c revision 1.13 1 /* $NetBSD: cmp.c,v 1.13 1998/10/08 23:30:35 wsanchez 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.13 1998/10/08 23:30:35 wsanchez 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 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
80 else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec)
81 return (1);
82 else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec)
83 return (-1);
84 #else
85 else if (b->fts_statp->st_mtimespec.ts_nsec > a->fts_statp->st_mtimespec.ts_nsec)
86 return (1);
87 else if (b->fts_statp->st_mtimespec.ts_nsec < a->fts_statp->st_mtimespec.ts_nsec)
88 return (-1);
89 #endif
90 else
91 return (namecmp(a, b));
92 }
93
94 int
95 revmodcmp(a, b)
96 const FTSENT *a, *b;
97 {
98 if (b->fts_statp->st_mtime > a->fts_statp->st_mtime)
99 return (-1);
100 else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime)
101 return (1);
102 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
103 else if (b->fts_statp->st_mtimensec > a->fts_statp->st_mtimensec)
104 return (-1);
105 else if (b->fts_statp->st_mtimensec < a->fts_statp->st_mtimensec)
106 return (1);
107 #else
108 else if (b->fts_statp->st_mtimespec.ts_nsec > a->fts_statp->st_mtimespec.ts_nsec)
109 return (-1);
110 else if (b->fts_statp->st_mtimespec.ts_nsec < a->fts_statp->st_mtimespec.ts_nsec)
111 return (1);
112 #endif
113 else
114 return (revnamecmp(a, b));
115 }
116
117 int
118 acccmp(a, b)
119 const FTSENT *a, *b;
120 {
121 if (b->fts_statp->st_atime > a->fts_statp->st_atime)
122 return (1);
123 else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
124 return (-1);
125 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
126 else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec)
127 return (1);
128 else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec)
129 return (-1);
130 #else
131 else if (b->fts_statp->st_atimespec.ts_nsec > a->fts_statp->st_atimespec.ts_nsec)
132 return (1);
133 else if (b->fts_statp->st_atimespec.ts_nsec < a->fts_statp->st_atimespec.ts_nsec)
134 return (-1);
135 #endif
136 else
137 return (namecmp(a, b));
138 }
139
140 int
141 revacccmp(a, b)
142 const FTSENT *a, *b;
143 {
144 if (b->fts_statp->st_atime > a->fts_statp->st_atime)
145 return (-1);
146 else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
147 return (1);
148 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
149 else if (b->fts_statp->st_atimensec > a->fts_statp->st_atimensec)
150 return (-1);
151 else if (b->fts_statp->st_atimensec < a->fts_statp->st_atimensec)
152 return (1);
153 #else
154 else if (b->fts_statp->st_atimespec.ts_nsec > a->fts_statp->st_atimespec.ts_nsec)
155 return (-1);
156 else if (b->fts_statp->st_atimespec.ts_nsec < a->fts_statp->st_atimespec.ts_nsec)
157 return (1);
158 #endif
159 else
160 return (revnamecmp(a, b));
161 }
162
163 int
164 statcmp(a, b)
165 const FTSENT *a, *b;
166 {
167 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
168 return (1);
169 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
170 return (-1);
171 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
172 else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec)
173 return (1);
174 else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec)
175 return (-1);
176 #else
177 else if (b->fts_statp->st_ctimespec.ts_nsec > a->fts_statp->st_ctimespec.ts_nsec)
178 return (1);
179 else if (b->fts_statp->st_ctimespec.ts_nsec < a->fts_statp->st_ctimespec.ts_nsec)
180 return (-1);
181 #endif
182 else
183 return (namecmp(a, b));
184 }
185
186 int
187 revstatcmp(a, b)
188 const FTSENT *a, *b;
189 {
190 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
191 return (-1);
192 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
193 return (1);
194 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || defined (_XOPEN_SOURCE)
195 else if (b->fts_statp->st_ctimensec > a->fts_statp->st_ctimensec)
196 return (-1);
197 else if (b->fts_statp->st_ctimensec < a->fts_statp->st_ctimensec)
198 return (1);
199 #else
200 else if (b->fts_statp->st_ctimespec.ts_nsec > a->fts_statp->st_ctimespec.ts_nsec)
201 return (-1);
202 else if (b->fts_statp->st_ctimespec.ts_nsec < a->fts_statp->st_ctimespec.ts_nsec)
203 return (1);
204 #endif
205 else
206 return (revnamecmp(a, b));
207 }
208
209 int
210 sizecmp(a, b)
211 const FTSENT *a, *b;
212 {
213 if (b->fts_statp->st_size > a->fts_statp->st_size)
214 return (1);
215 if (b->fts_statp->st_size < a->fts_statp->st_size)
216 return (-1);
217 else
218 return (namecmp(a, b));
219 }
220
221 int
222 revsizecmp(a, b)
223 const FTSENT *a, *b;
224 {
225 if (b->fts_statp->st_size > a->fts_statp->st_size)
226 return (-1);
227 if (b->fts_statp->st_size < a->fts_statp->st_size)
228 return (1);
229 else
230 return (revnamecmp(a, b));
231 }
232