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 * 3. 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
32 * @(#)cmp.c 8.1 (Berkeley) 5/31/93
33 * $FreeBSD: src/bin/ls/cmp.c,v 1.16 2005/01/10 08:39:23 imp Exp $
36 #include <sys/types.h>
46 namecmp(const FTSENT
*a
, const FTSENT
*b
)
48 return (strcoll(a
->fts_name
, b
->fts_name
));
52 revnamecmp(const FTSENT
*a
, const FTSENT
*b
)
54 return (strcoll(b
->fts_name
, a
->fts_name
));
58 modcmp(const FTSENT
*a
, const FTSENT
*b
)
60 if (b
->fts_statp
->st_mtimespec
.tv_sec
>
61 a
->fts_statp
->st_mtimespec
.tv_sec
)
63 if (b
->fts_statp
->st_mtimespec
.tv_sec
<
64 a
->fts_statp
->st_mtimespec
.tv_sec
)
66 if (b
->fts_statp
->st_mtimespec
.tv_nsec
>
67 a
->fts_statp
->st_mtimespec
.tv_nsec
)
69 if (b
->fts_statp
->st_mtimespec
.tv_nsec
<
70 a
->fts_statp
->st_mtimespec
.tv_nsec
)
72 return (strcoll(a
->fts_name
, b
->fts_name
));
76 revmodcmp(const FTSENT
*a
, const FTSENT
*b
)
78 return (modcmp(b
, a
));
82 acccmp(const FTSENT
*a
, const FTSENT
*b
)
84 if (b
->fts_statp
->st_atimespec
.tv_sec
>
85 a
->fts_statp
->st_atimespec
.tv_sec
)
87 if (b
->fts_statp
->st_atimespec
.tv_sec
<
88 a
->fts_statp
->st_atimespec
.tv_sec
)
90 if (b
->fts_statp
->st_atimespec
.tv_nsec
>
91 a
->fts_statp
->st_atimespec
.tv_nsec
)
93 if (b
->fts_statp
->st_atimespec
.tv_nsec
<
94 a
->fts_statp
->st_atimespec
.tv_nsec
)
96 return (strcoll(a
->fts_name
, b
->fts_name
));
100 revacccmp(const FTSENT
*a
, const FTSENT
*b
)
102 return (acccmp(b
, a
));
106 sizecmp(const FTSENT
*a
, const FTSENT
*b
)
108 if (b
->fts_statp
->st_size
>
109 a
->fts_statp
->st_size
)
111 if (b
->fts_statp
->st_size
<
112 a
->fts_statp
->st_size
)
114 return (strcoll(a
->fts_name
, b
->fts_name
));
118 revsizecmp(const FTSENT
*a
, const FTSENT
*b
)
120 return (sizecmp(b
, a
));
124 statcmp(const FTSENT
*a
, const FTSENT
*b
)
126 if (b
->fts_statp
->st_ctimespec
.tv_sec
>
127 a
->fts_statp
->st_ctimespec
.tv_sec
)
129 if (b
->fts_statp
->st_ctimespec
.tv_sec
<
130 a
->fts_statp
->st_ctimespec
.tv_sec
)
132 if (b
->fts_statp
->st_ctimespec
.tv_nsec
>
133 a
->fts_statp
->st_ctimespec
.tv_nsec
)
135 if (b
->fts_statp
->st_ctimespec
.tv_nsec
<
136 a
->fts_statp
->st_ctimespec
.tv_nsec
)
138 return (strcoll(a
->fts_name
, b
->fts_name
));
142 revstatcmp(const FTSENT
*a
, const FTSENT
*b
)
144 return (statcmp(b
, a
));