File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038
0039 #if 0
0040 #include <sys/cdefs.h>
0041 #ifndef lint
0042 #if 0
0043 static char sccsid[] = "@(#)cmp.c 8.1 (Berkeley) 5/31/93";
0044 #else
0045 __RCSID("$NetBSD: cmp.c,v 1.17 2003/08/07 09:05:14 agc Exp $");
0046 #endif
0047 #endif
0048 #endif
0049
0050 #include <sys/types.h>
0051 #include <sys/stat.h>
0052
0053 #include "fts.h"
0054 #include <string.h>
0055
0056 #include "extern-ls.h"
0057
0058 #if defined(__rtems__) || defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
0059 defined(_XOPEN_SOURCE) || defined(__NetBSD__)
0060 #define ATIMENSEC_CMP(x, op, y) ((x)->st_atime op (y)->st_atime)
0061 #define CTIMENSEC_CMP(x, op, y) ((x)->st_ctime op (y)->st_ctime)
0062 #define MTIMENSEC_CMP(x, op, y) ((x)->st_mtime op (y)->st_mtime)
0063 #else
0064 #define ATIMENSEC_CMP(x, op, y) \
0065 ((x)->st_atime.tv_nsec op (y)->st_atime.tv_nsec)
0066 #define CTIMENSEC_CMP(x, op, y) \
0067 ((x)->st_ctime.tv_nsec op (y)->st_ctime.tv_nsec)
0068 #define MTIMENSEC_CMP(x, op, y) \
0069 ((x)->st_mtime.tv_nsec op (y)->st_mtime.tv_nsec)
0070 #endif
0071
0072 int
0073 namecmp(const FTSENT *a, const FTSENT *b)
0074 {
0075
0076 return (strcmp(a->fts_name, b->fts_name));
0077 }
0078
0079 int
0080 revnamecmp(const FTSENT *a, const FTSENT *b)
0081 {
0082
0083 return (strcmp(b->fts_name, a->fts_name));
0084 }
0085
0086 int
0087 modcmp(const FTSENT *a, const FTSENT *b)
0088 {
0089
0090 if (b->fts_statp->st_mtime > a->fts_statp->st_mtime)
0091 return (1);
0092 else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime)
0093 return (-1);
0094 else if (MTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0095 return (1);
0096 else if (MTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0097 return (-1);
0098 else
0099 return (namecmp(a, b));
0100 }
0101
0102 int
0103 revmodcmp(const FTSENT *a, const FTSENT *b)
0104 {
0105
0106 if (b->fts_statp->st_mtime > a->fts_statp->st_mtime)
0107 return (-1);
0108 else if (b->fts_statp->st_mtime < a->fts_statp->st_mtime)
0109 return (1);
0110 else if (MTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0111 return (-1);
0112 else if (MTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0113 return (1);
0114 else
0115 return (revnamecmp(a, b));
0116 }
0117
0118 int
0119 acccmp(const FTSENT *a, const FTSENT *b)
0120 {
0121
0122 if (b->fts_statp->st_atime > a->fts_statp->st_atime)
0123 return (1);
0124 else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
0125 return (-1);
0126 else if (ATIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0127 return (1);
0128 else if (ATIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0129 return (-1);
0130 else
0131 return (namecmp(a, b));
0132 }
0133
0134 int
0135 revacccmp(const FTSENT *a, const FTSENT *b)
0136 {
0137
0138 if (b->fts_statp->st_atime > a->fts_statp->st_atime)
0139 return (-1);
0140 else if (b->fts_statp->st_atime < a->fts_statp->st_atime)
0141 return (1);
0142 else if (ATIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0143 return (-1);
0144 else if (ATIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0145 return (1);
0146 else
0147 return (revnamecmp(a, b));
0148 }
0149
0150 int
0151 statcmp(const FTSENT *a, const FTSENT *b)
0152 {
0153
0154 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
0155 return (1);
0156 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
0157 return (-1);
0158 else if (CTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0159 return (1);
0160 else if (CTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0161 return (-1);
0162 else
0163 return (namecmp(a, b));
0164 }
0165
0166 int
0167 revstatcmp(const FTSENT *a, const FTSENT *b)
0168 {
0169
0170 if (b->fts_statp->st_ctime > a->fts_statp->st_ctime)
0171 return (-1);
0172 else if (b->fts_statp->st_ctime < a->fts_statp->st_ctime)
0173 return (1);
0174 else if (CTIMENSEC_CMP(b->fts_statp, >, a->fts_statp))
0175 return (-1);
0176 else if (CTIMENSEC_CMP(b->fts_statp, <, a->fts_statp))
0177 return (1);
0178 else
0179 return (revnamecmp(a, b));
0180 }
0181
0182 int
0183 sizecmp(const FTSENT *a, const FTSENT *b)
0184 {
0185
0186 if (b->fts_statp->st_size > a->fts_statp->st_size)
0187 return (1);
0188 if (b->fts_statp->st_size < a->fts_statp->st_size)
0189 return (-1);
0190 else
0191 return (namecmp(a, b));
0192 }
0193
0194 int
0195 revsizecmp(const FTSENT *a, const FTSENT *b)
0196 {
0197
0198 if (b->fts_statp->st_size > a->fts_statp->st_size)
0199 return (-1);
0200 if (b->fts_statp->st_size < a->fts_statp->st_size)
0201 return (1);
0202 else
0203 return (revnamecmp(a, b));
0204 }