1 /* $NetBSD: cmp.c,v 1.17 2003/08/07 09:05:14 agc Exp $ */
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
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
40 __RCSID("$NetBSD: cmp.c,v 1.17 2003/08/07 09:05:14 agc Exp $");
44 #include <sys/types.h>
53 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
54 defined(_XOPEN_SOURCE) || defined(__NetBSD__)
55 #define ATIMENSEC_CMP(x, op, y) ((x)->st_atimensec op (y)->st_atimensec)
56 #define CTIMENSEC_CMP(x, op, y) ((x)->st_ctimensec op (y)->st_ctimensec)
57 #define MTIMENSEC_CMP(x, op, y) ((x)->st_mtimensec op (y)->st_mtimensec)
59 #define ATIMENSEC_CMP(x, op, y) \
60 ((x)->st_atimespec.tv_nsec op (y)->st_atimespec.tv_nsec)
61 #define CTIMENSEC_CMP(x, op, y) \
62 ((x)->st_ctimespec.tv_nsec op (y)->st_ctimespec.tv_nsec)
63 #define MTIMENSEC_CMP(x, op, y) \
64 ((x)->st_mtimespec.tv_nsec op (y)->st_mtimespec.tv_nsec)
68 namecmp(const FTSENT
*a
, const FTSENT
*b
)
71 return (strcmp(a
->fts_name
, b
->fts_name
));
75 revnamecmp(const FTSENT
*a
, const FTSENT
*b
)
78 return (strcmp(b
->fts_name
, a
->fts_name
));
82 modcmp(const FTSENT
*a
, const FTSENT
*b
)
85 if (b
->fts_statp
->st_mtime
> a
->fts_statp
->st_mtime
)
87 else if (b
->fts_statp
->st_mtime
< a
->fts_statp
->st_mtime
)
89 else if (MTIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
91 else if (MTIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
94 return (namecmp(a
, b
));
98 revmodcmp(const FTSENT
*a
, const FTSENT
*b
)
101 if (b
->fts_statp
->st_mtime
> a
->fts_statp
->st_mtime
)
103 else if (b
->fts_statp
->st_mtime
< a
->fts_statp
->st_mtime
)
105 else if (MTIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
107 else if (MTIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
110 return (revnamecmp(a
, b
));
114 acccmp(const FTSENT
*a
, const FTSENT
*b
)
117 if (b
->fts_statp
->st_atime
> a
->fts_statp
->st_atime
)
119 else if (b
->fts_statp
->st_atime
< a
->fts_statp
->st_atime
)
121 else if (ATIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
123 else if (ATIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
126 return (namecmp(a
, b
));
130 revacccmp(const FTSENT
*a
, const FTSENT
*b
)
133 if (b
->fts_statp
->st_atime
> a
->fts_statp
->st_atime
)
135 else if (b
->fts_statp
->st_atime
< a
->fts_statp
->st_atime
)
137 else if (ATIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
139 else if (ATIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
142 return (revnamecmp(a
, b
));
146 statcmp(const FTSENT
*a
, const FTSENT
*b
)
149 if (b
->fts_statp
->st_ctime
> a
->fts_statp
->st_ctime
)
151 else if (b
->fts_statp
->st_ctime
< a
->fts_statp
->st_ctime
)
153 else if (CTIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
155 else if (CTIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
158 return (namecmp(a
, b
));
162 revstatcmp(const FTSENT
*a
, const FTSENT
*b
)
165 if (b
->fts_statp
->st_ctime
> a
->fts_statp
->st_ctime
)
167 else if (b
->fts_statp
->st_ctime
< a
->fts_statp
->st_ctime
)
169 else if (CTIMENSEC_CMP(b
->fts_statp
, >, a
->fts_statp
))
171 else if (CTIMENSEC_CMP(b
->fts_statp
, <, a
->fts_statp
))
174 return (revnamecmp(a
, b
));
178 sizecmp(const FTSENT
*a
, const FTSENT
*b
)
181 if (b
->fts_statp
->st_size
> a
->fts_statp
->st_size
)
183 if (b
->fts_statp
->st_size
< a
->fts_statp
->st_size
)
186 return (namecmp(a
, b
));
190 revsizecmp(const FTSENT
*a
, const FTSENT
*b
)
193 if (b
->fts_statp
->st_size
> a
->fts_statp
->st_size
)
195 if (b
->fts_statp
->st_size
< a
->fts_statp
->st_size
)
198 return (revnamecmp(a
, b
));