2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 4. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
42 #include <sys/types.h>
52 namecmp(const FTSENT *a, const FTSENT *b)
55 return (strcoll(a->fts_name, b->fts_name));
59 revnamecmp(const FTSENT *a, const FTSENT *b)
62 return (strcoll(b->fts_name, a->fts_name));
66 modcmp(const FTSENT *a, const FTSENT *b)
69 if (b->fts_statp->st_mtim.tv_sec >
70 a->fts_statp->st_mtim.tv_sec)
72 if (b->fts_statp->st_mtim.tv_sec <
73 a->fts_statp->st_mtim.tv_sec)
75 if (b->fts_statp->st_mtim.tv_nsec >
76 a->fts_statp->st_mtim.tv_nsec)
78 if (b->fts_statp->st_mtim.tv_nsec <
79 a->fts_statp->st_mtim.tv_nsec)
82 return (strcoll(b->fts_name, a->fts_name));
84 return (strcoll(a->fts_name, b->fts_name));
88 revmodcmp(const FTSENT *a, const FTSENT *b)
91 return (modcmp(b, a));
95 acccmp(const FTSENT *a, const FTSENT *b)
98 if (b->fts_statp->st_atim.tv_sec >
99 a->fts_statp->st_atim.tv_sec)
101 if (b->fts_statp->st_atim.tv_sec <
102 a->fts_statp->st_atim.tv_sec)
104 if (b->fts_statp->st_atim.tv_nsec >
105 a->fts_statp->st_atim.tv_nsec)
107 if (b->fts_statp->st_atim.tv_nsec <
108 a->fts_statp->st_atim.tv_nsec)
111 return (strcoll(b->fts_name, a->fts_name));
113 return (strcoll(a->fts_name, b->fts_name));
117 revacccmp(const FTSENT *a, const FTSENT *b)
120 return (acccmp(b, a));
124 birthcmp(const FTSENT *a, const FTSENT *b)
127 if (b->fts_statp->st_birthtim.tv_sec >
128 a->fts_statp->st_birthtim.tv_sec)
130 if (b->fts_statp->st_birthtim.tv_sec <
131 a->fts_statp->st_birthtim.tv_sec)
133 if (b->fts_statp->st_birthtim.tv_nsec >
134 a->fts_statp->st_birthtim.tv_nsec)
136 if (b->fts_statp->st_birthtim.tv_nsec <
137 a->fts_statp->st_birthtim.tv_nsec)
140 return (strcoll(b->fts_name, a->fts_name));
142 return (strcoll(a->fts_name, b->fts_name));
146 revbirthcmp(const FTSENT *a, const FTSENT *b)
149 return (birthcmp(b, a));
153 statcmp(const FTSENT *a, const FTSENT *b)
156 if (b->fts_statp->st_ctim.tv_sec >
157 a->fts_statp->st_ctim.tv_sec)
159 if (b->fts_statp->st_ctim.tv_sec <
160 a->fts_statp->st_ctim.tv_sec)
162 if (b->fts_statp->st_ctim.tv_nsec >
163 a->fts_statp->st_ctim.tv_nsec)
165 if (b->fts_statp->st_ctim.tv_nsec <
166 a->fts_statp->st_ctim.tv_nsec)
169 return (strcoll(b->fts_name, a->fts_name));
171 return (strcoll(a->fts_name, b->fts_name));
175 revstatcmp(const FTSENT *a, const FTSENT *b)
178 return (statcmp(b, a));
182 sizecmp(const FTSENT *a, const FTSENT *b)
185 if (b->fts_statp->st_size > a->fts_statp->st_size)
187 if (b->fts_statp->st_size < a->fts_statp->st_size)
189 return (strcoll(a->fts_name, b->fts_name));
193 revsizecmp(const FTSENT *a, const FTSENT *b)
196 return (sizecmp(b, a));