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
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 $
34 * $DragonFly: src/bin/ls/cmp.c,v 1.7 2008/01/19 15:33:42 matthias Exp $
37 #include <sys/types.h>
47 namecmp(const FTSENT
*a
, const FTSENT
*b
)
49 return(strcoll(a
->fts_name
, b
->fts_name
));
53 revnamecmp(const FTSENT
*a
, const FTSENT
*b
)
55 return(strcoll(b
->fts_name
, a
->fts_name
));
59 modcmp(const FTSENT
*a
, const FTSENT
*b
)
61 if (b
->fts_statp
->st_mtimespec
.tv_sec
>
62 a
->fts_statp
->st_mtimespec
.tv_sec
)
64 if (b
->fts_statp
->st_mtimespec
.tv_sec
<
65 a
->fts_statp
->st_mtimespec
.tv_sec
)
67 if (b
->fts_statp
->st_mtimespec
.tv_nsec
>
68 a
->fts_statp
->st_mtimespec
.tv_nsec
)
70 if (b
->fts_statp
->st_mtimespec
.tv_nsec
<
71 a
->fts_statp
->st_mtimespec
.tv_nsec
)
73 return(strcoll(a
->fts_name
, b
->fts_name
));
77 revmodcmp(const FTSENT
*a
, const FTSENT
*b
)
83 acccmp(const FTSENT
*a
, const FTSENT
*b
)
85 if (b
->fts_statp
->st_atimespec
.tv_sec
>
86 a
->fts_statp
->st_atimespec
.tv_sec
)
88 if (b
->fts_statp
->st_atimespec
.tv_sec
<
89 a
->fts_statp
->st_atimespec
.tv_sec
)
91 if (b
->fts_statp
->st_atimespec
.tv_nsec
>
92 a
->fts_statp
->st_atimespec
.tv_nsec
)
94 if (b
->fts_statp
->st_atimespec
.tv_nsec
<
95 a
->fts_statp
->st_atimespec
.tv_nsec
)
97 return(strcoll(a
->fts_name
, b
->fts_name
));
101 revacccmp(const FTSENT
*a
, const FTSENT
*b
)
103 return(acccmp(b
, a
));
107 sizecmp(const FTSENT
*a
, const FTSENT
*b
)
109 if (b
->fts_statp
->st_size
>
110 a
->fts_statp
->st_size
)
112 if (b
->fts_statp
->st_size
<
113 a
->fts_statp
->st_size
)
115 return(strcoll(a
->fts_name
, b
->fts_name
));
119 revsizecmp(const FTSENT
*a
, const FTSENT
*b
)
121 return(sizecmp(b
, a
));
125 statcmp(const FTSENT
*a
, const FTSENT
*b
)
127 if (b
->fts_statp
->st_ctimespec
.tv_sec
>
128 a
->fts_statp
->st_ctimespec
.tv_sec
)
130 if (b
->fts_statp
->st_ctimespec
.tv_sec
<
131 a
->fts_statp
->st_ctimespec
.tv_sec
)
133 if (b
->fts_statp
->st_ctimespec
.tv_nsec
>
134 a
->fts_statp
->st_ctimespec
.tv_nsec
)
136 if (b
->fts_statp
->st_ctimespec
.tv_nsec
<
137 a
->fts_statp
->st_ctimespec
.tv_nsec
)
139 return(strcoll(a
->fts_name
, b
->fts_name
));
143 revstatcmp(const FTSENT
*a
, const FTSENT
*b
)
145 return(statcmp(b
, a
));