2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
44 #include <sys/types.h>
54 namecmp(const FTSENT *a, const FTSENT *b)
57 return (strcoll(a->fts_name, b->fts_name));
61 revnamecmp(const FTSENT *a, const FTSENT *b)
64 return (strcoll(b->fts_name, a->fts_name));
68 verscmp(const FTSENT *a, const FTSENT *b)
71 return (strverscmp(a->fts_name, b->fts_name));
75 revverscmp(const FTSENT *a, const FTSENT *b)
78 return (strverscmp(b->fts_name, a->fts_name));
82 modcmp(const FTSENT *a, const FTSENT *b)
85 if (b->fts_statp->st_mtim.tv_sec >
86 a->fts_statp->st_mtim.tv_sec)
88 if (b->fts_statp->st_mtim.tv_sec <
89 a->fts_statp->st_mtim.tv_sec)
91 if (b->fts_statp->st_mtim.tv_nsec >
92 a->fts_statp->st_mtim.tv_nsec)
94 if (b->fts_statp->st_mtim.tv_nsec <
95 a->fts_statp->st_mtim.tv_nsec)
98 return (strcoll(b->fts_name, a->fts_name));
100 return (strcoll(a->fts_name, b->fts_name));
104 revmodcmp(const FTSENT *a, const FTSENT *b)
107 return (modcmp(b, a));
111 acccmp(const FTSENT *a, const FTSENT *b)
114 if (b->fts_statp->st_atim.tv_sec >
115 a->fts_statp->st_atim.tv_sec)
117 if (b->fts_statp->st_atim.tv_sec <
118 a->fts_statp->st_atim.tv_sec)
120 if (b->fts_statp->st_atim.tv_nsec >
121 a->fts_statp->st_atim.tv_nsec)
123 if (b->fts_statp->st_atim.tv_nsec <
124 a->fts_statp->st_atim.tv_nsec)
127 return (strcoll(b->fts_name, a->fts_name));
129 return (strcoll(a->fts_name, b->fts_name));
133 revacccmp(const FTSENT *a, const FTSENT *b)
136 return (acccmp(b, a));
140 birthcmp(const FTSENT *a, const FTSENT *b)
143 if (b->fts_statp->st_birthtim.tv_sec >
144 a->fts_statp->st_birthtim.tv_sec)
146 if (b->fts_statp->st_birthtim.tv_sec <
147 a->fts_statp->st_birthtim.tv_sec)
149 if (b->fts_statp->st_birthtim.tv_nsec >
150 a->fts_statp->st_birthtim.tv_nsec)
152 if (b->fts_statp->st_birthtim.tv_nsec <
153 a->fts_statp->st_birthtim.tv_nsec)
156 return (strcoll(b->fts_name, a->fts_name));
158 return (strcoll(a->fts_name, b->fts_name));
162 revbirthcmp(const FTSENT *a, const FTSENT *b)
165 return (birthcmp(b, a));
169 statcmp(const FTSENT *a, const FTSENT *b)
172 if (b->fts_statp->st_ctim.tv_sec >
173 a->fts_statp->st_ctim.tv_sec)
175 if (b->fts_statp->st_ctim.tv_sec <
176 a->fts_statp->st_ctim.tv_sec)
178 if (b->fts_statp->st_ctim.tv_nsec >
179 a->fts_statp->st_ctim.tv_nsec)
181 if (b->fts_statp->st_ctim.tv_nsec <
182 a->fts_statp->st_ctim.tv_nsec)
185 return (strcoll(b->fts_name, a->fts_name));
187 return (strcoll(a->fts_name, b->fts_name));
191 revstatcmp(const FTSENT *a, const FTSENT *b)
194 return (statcmp(b, a));
198 sizecmp(const FTSENT *a, const FTSENT *b)
201 if (b->fts_statp->st_size > a->fts_statp->st_size)
203 if (b->fts_statp->st_size < a->fts_statp->st_size)
205 return (strcoll(a->fts_name, b->fts_name));
209 revsizecmp(const FTSENT *a, const FTSENT *b)
212 return (sizecmp(b, a));