1139969Simp/*-
21556Srgrimes * Copyright (c) 1989, 1993
31556Srgrimes *	The Regents of the University of California.  All rights reserved.
41556Srgrimes *
51556Srgrimes * This code is derived from software contributed to Berkeley by
61556Srgrimes * Michael Fischbein.
71556Srgrimes *
81556Srgrimes * Redistribution and use in source and binary forms, with or without
91556Srgrimes * modification, are permitted provided that the following conditions
101556Srgrimes * are met:
111556Srgrimes * 1. Redistributions of source code must retain the above copyright
121556Srgrimes *    notice, this list of conditions and the following disclaimer.
131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141556Srgrimes *    notice, this list of conditions and the following disclaimer in the
151556Srgrimes *    documentation and/or other materials provided with the distribution.
161556Srgrimes * 4. Neither the name of the University nor the names of its contributors
171556Srgrimes *    may be used to endorse or promote products derived from this software
181556Srgrimes *    without specific prior written permission.
191556Srgrimes *
201556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301556Srgrimes * SUCH DAMAGE.
311556Srgrimes */
321556Srgrimes
3390153Smarkm#if 0
341556Srgrimes#ifndef lint
3527967Sstevestatic char sccsid[] = "@(#)cmp.c	8.1 (Berkeley) 5/31/93";
3690153Smarkm#endif /* not lint */
3727967Ssteve#endif
3899109Sobrien#include <sys/cdefs.h>
3999109Sobrien__FBSDID("$FreeBSD$");
401556Srgrimes
4199109Sobrien
421556Srgrimes#include <sys/types.h>
431556Srgrimes#include <sys/stat.h>
441556Srgrimes
451556Srgrimes#include <fts.h>
461556Srgrimes#include <string.h>
471556Srgrimes
481556Srgrimes#include "ls.h"
491556Srgrimes#include "extern.h"
501556Srgrimes
511556Srgrimesint
5290110Simpnamecmp(const FTSENT *a, const FTSENT *b)
531556Srgrimes{
54130967Sdwmalone
5520960Sache	return (strcoll(a->fts_name, b->fts_name));
561556Srgrimes}
571556Srgrimes
581556Srgrimesint
5990110Simprevnamecmp(const FTSENT *a, const FTSENT *b)
601556Srgrimes{
61130967Sdwmalone
6220960Sache	return (strcoll(b->fts_name, a->fts_name));
631556Srgrimes}
641556Srgrimes
651556Srgrimesint
6690110Simpmodcmp(const FTSENT *a, const FTSENT *b)
671556Srgrimes{
68130967Sdwmalone
69205793Sed	if (b->fts_statp->st_mtim.tv_sec >
70205793Sed	    a->fts_statp->st_mtim.tv_sec)
71130967Sdwmalone		return (1);
72205793Sed	if (b->fts_statp->st_mtim.tv_sec <
73205793Sed	    a->fts_statp->st_mtim.tv_sec)
74130967Sdwmalone		return (-1);
75205793Sed	if (b->fts_statp->st_mtim.tv_nsec >
76205793Sed	    a->fts_statp->st_mtim.tv_nsec)
77130967Sdwmalone		return (1);
78205793Sed	if (b->fts_statp->st_mtim.tv_nsec <
79205793Sed	    a->fts_statp->st_mtim.tv_nsec)
80130967Sdwmalone		return (-1);
81242807Sgrog	if (f_samesort)
82242725Sgrog		return (strcoll(b->fts_name, a->fts_name));
83242807Sgrog	else
84242725Sgrog		return (strcoll(a->fts_name, b->fts_name));
851556Srgrimes}
861556Srgrimes
871556Srgrimesint
8890110Simprevmodcmp(const FTSENT *a, const FTSENT *b)
891556Srgrimes{
90130967Sdwmalone
91130967Sdwmalone	return (modcmp(b, a));
921556Srgrimes}
931556Srgrimes
941556Srgrimesint
9590110Simpacccmp(const FTSENT *a, const FTSENT *b)
961556Srgrimes{
97130967Sdwmalone
98205793Sed	if (b->fts_statp->st_atim.tv_sec >
99205793Sed	    a->fts_statp->st_atim.tv_sec)
100130967Sdwmalone		return (1);
101205793Sed	if (b->fts_statp->st_atim.tv_sec <
102205793Sed	    a->fts_statp->st_atim.tv_sec)
103130967Sdwmalone		return (-1);
104205793Sed	if (b->fts_statp->st_atim.tv_nsec >
105205793Sed	    a->fts_statp->st_atim.tv_nsec)
106130967Sdwmalone		return (1);
107205793Sed	if (b->fts_statp->st_atim.tv_nsec <
108205793Sed	    a->fts_statp->st_atim.tv_nsec)
109130967Sdwmalone		return (-1);
110242807Sgrog	if (f_samesort)
111242725Sgrog		return (strcoll(b->fts_name, a->fts_name));
112242807Sgrog	else
113242725Sgrog		return (strcoll(a->fts_name, b->fts_name));
1141556Srgrimes}
1151556Srgrimes
1161556Srgrimesint
11790110Simprevacccmp(const FTSENT *a, const FTSENT *b)
1181556Srgrimes{
119130967Sdwmalone
120130967Sdwmalone	return (acccmp(b, a));
1211556Srgrimes}
1221556Srgrimes
1231556Srgrimesint
124157098Sjhbbirthcmp(const FTSENT *a, const FTSENT *b)
125157098Sjhb{
126157098Sjhb
127205793Sed	if (b->fts_statp->st_birthtim.tv_sec >
128205793Sed	    a->fts_statp->st_birthtim.tv_sec)
129157098Sjhb		return (1);
130205793Sed	if (b->fts_statp->st_birthtim.tv_sec <
131205793Sed	    a->fts_statp->st_birthtim.tv_sec)
132157098Sjhb		return (-1);
133205793Sed	if (b->fts_statp->st_birthtim.tv_nsec >
134205793Sed	    a->fts_statp->st_birthtim.tv_nsec)
135157098Sjhb		return (1);
136205793Sed	if (b->fts_statp->st_birthtim.tv_nsec <
137205793Sed	    a->fts_statp->st_birthtim.tv_nsec)
138157098Sjhb		return (-1);
139242807Sgrog	if (f_samesort)
140242725Sgrog		return (strcoll(b->fts_name, a->fts_name));
141242807Sgrog	else
142242725Sgrog		return (strcoll(a->fts_name, b->fts_name));
143157098Sjhb}
144157098Sjhb
145157098Sjhbint
146157098Sjhbrevbirthcmp(const FTSENT *a, const FTSENT *b)
147157098Sjhb{
148157098Sjhb
149157098Sjhb	return (birthcmp(b, a));
150157098Sjhb}
151157098Sjhb
152157098Sjhbint
15390110Simpstatcmp(const FTSENT *a, const FTSENT *b)
1541556Srgrimes{
155130967Sdwmalone
156205793Sed	if (b->fts_statp->st_ctim.tv_sec >
157205793Sed	    a->fts_statp->st_ctim.tv_sec)
158130967Sdwmalone		return (1);
159205793Sed	if (b->fts_statp->st_ctim.tv_sec <
160205793Sed	    a->fts_statp->st_ctim.tv_sec)
161130967Sdwmalone		return (-1);
162205793Sed	if (b->fts_statp->st_ctim.tv_nsec >
163205793Sed	    a->fts_statp->st_ctim.tv_nsec)
164130967Sdwmalone		return (1);
165205793Sed	if (b->fts_statp->st_ctim.tv_nsec <
166205793Sed	    a->fts_statp->st_ctim.tv_nsec)
167130967Sdwmalone		return (-1);
168242807Sgrog	if (f_samesort)
169242725Sgrog		return (strcoll(b->fts_name, a->fts_name));
170242807Sgrog	else
171242725Sgrog		return (strcoll(a->fts_name, b->fts_name));
1721556Srgrimes}
1731556Srgrimes
1741556Srgrimesint
17590110Simprevstatcmp(const FTSENT *a, const FTSENT *b)
1761556Srgrimes{
177130967Sdwmalone
178130967Sdwmalone	return (statcmp(b, a));
1791556Srgrimes}
180146924Sdd
181146924Sddint
182146924Sddsizecmp(const FTSENT *a, const FTSENT *b)
183146924Sdd{
184146924Sdd
185146924Sdd	if (b->fts_statp->st_size > a->fts_statp->st_size)
186146924Sdd		return (1);
187146924Sdd	if (b->fts_statp->st_size < a->fts_statp->st_size)
188146924Sdd		return (-1);
189146924Sdd	return (strcoll(a->fts_name, b->fts_name));
190146924Sdd}
191146924Sdd
192146924Sddint
193146924Sddrevsizecmp(const FTSENT *a, const FTSENT *b)
194146924Sdd{
195146924Sdd
196146924Sdd	return (sizecmp(b, a));
197146924Sdd}
198