aboutsummaryrefslogtreecommitdiff
path: root/findutils
diff options
context:
space:
mode:
Diffstat (limited to 'findutils')
-rw-r--r--findutils/find.c147
1 files changed, 125 insertions, 22 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 188865e05..87f827b1f 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -67,21 +67,53 @@
67//config: interpreted by other programs. 67//config: interpreted by other programs.
68//config: 68//config:
69//config:config FEATURE_FIND_MTIME 69//config:config FEATURE_FIND_MTIME
70//config: bool "Enable -mtime: modified time matching" 70//config: bool "Enable -mtime: modification time matching"
71//config: default y 71//config: default y
72//config: depends on FIND 72//config: depends on FIND
73//config: help 73//config: help
74//config: Allow searching based on the modification time of 74//config: Allow searching based on the modification time of
75//config: files, in days. 75//config: files, in days.
76//config: 76//config:
77//config:config FEATURE_FIND_ATIME
78//config: bool "Enable -atime: access time matching"
79//config: default y
80//config: depends on FEATURE_FIND_MTIME
81//config: help
82//config: Allow searching based on the access time of
83//config: files, in days.
84//config:
85//config:config FEATURE_FIND_CTIME
86//config: bool "Enable -ctime: status change timestamp matching"
87//config: default y
88//config: depends on FEATURE_FIND_MTIME
89//config: help
90//config: Allow searching based on the status change timestamp of
91//config: files, in days.
92//config:
77//config:config FEATURE_FIND_MMIN 93//config:config FEATURE_FIND_MMIN
78//config: bool "Enable -mmin: modified time matching by minutes" 94//config: bool "Enable -mmin: modification time matching by minutes"
79//config: default y 95//config: default y
80//config: depends on FIND 96//config: depends on FIND
81//config: help 97//config: help
82//config: Allow searching based on the modification time of 98//config: Allow searching based on the modification time of
83//config: files, in minutes. 99//config: files, in minutes.
84//config: 100//config:
101//config:config FEATURE_FIND_AMIN
102//config: bool "Enable -amin: access time matching by minutes"
103//config: default y
104//config: depends on FEATURE_FIND_MMIN
105//config: help
106//config: Allow searching based on the access time of
107//config: files, in minutes.
108//config:
109//config:config FEATURE_FIND_CMIN
110//config: bool "Enable -cmin: status change timestamp matching by minutes"
111//config: default y
112//config: depends on FEATURE_FIND_MMIN
113//config: help
114//config: Allow searching based on the status change timestamp of
115//config: files, in minutes.
116//config:
85//config:config FEATURE_FIND_PERM 117//config:config FEATURE_FIND_PERM
86//config: bool "Enable -perm: permissions matching" 118//config: bool "Enable -perm: permissions matching"
87//config: default y 119//config: default y
@@ -296,10 +328,22 @@
296//usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N)," 328//usage: "\n -mtime DAYS mtime is greater than (+N), less than (-N),"
297//usage: "\n or exactly N days in the past" 329//usage: "\n or exactly N days in the past"
298//usage: ) 330//usage: )
331//usage: IF_FEATURE_FIND_ATIME(
332//usage: "\n -atime DAYS atime +N/-N/N days in the past"
333//usage: )
334//usage: IF_FEATURE_FIND_CTIME(
335//usage: "\n -ctime DAYS ctime +N/-N/N days in the past"
336//usage: )
299//usage: IF_FEATURE_FIND_MMIN( 337//usage: IF_FEATURE_FIND_MMIN(
300//usage: "\n -mmin MINS mtime is greater than (+N), less than (-N)," 338//usage: "\n -mmin MINS mtime is greater than (+N), less than (-N),"
301//usage: "\n or exactly N minutes in the past" 339//usage: "\n or exactly N minutes in the past"
302//usage: ) 340//usage: )
341//usage: IF_FEATURE_FIND_AMIN(
342//usage: "\n -amin MINS atime +N/-N/N minutes in the past"
343//usage: )
344//usage: IF_FEATURE_FIND_CMIN(
345//usage: "\n -cmin MINS ctime +N/-N/N minutes in the past"
346//usage: )
303//usage: IF_FEATURE_FIND_NEWER( 347//usage: IF_FEATURE_FIND_NEWER(
304//usage: "\n -newer FILE mtime is more recent than FILE's" 348//usage: "\n -newer FILE mtime is more recent than FILE's"
305//usage: ) 349//usage: )
@@ -396,8 +440,8 @@ IF_FEATURE_FIND_PRINT0( ACTS(print0))
396IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) 440IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
397IF_FEATURE_FIND_EXECUTABLE(ACTS(executable)) 441IF_FEATURE_FIND_EXECUTABLE(ACTS(executable))
398IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;)) 442IF_FEATURE_FIND_PERM( ACTS(perm, char perm_char; mode_t perm_mask;))
399IF_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; unsigned mtime_days;)) 443IF_FEATURE_FIND_MTIME( ACTS(mtime, unsigned char time_type; unsigned char mtime_char; unsigned mtime_days;))
400IF_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; unsigned mmin_mins;)) 444IF_FEATURE_FIND_MMIN( ACTS(mmin, unsigned char time_type; unsigned char mmin_char; unsigned mmin_mins;))
401IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) 445IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
402IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) 446IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
403IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) 447IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
@@ -618,30 +662,61 @@ ACTF(perm)
618 return (statbuf->st_mode & 07777) == ap->perm_mask; 662 return (statbuf->st_mode & 07777) == ap->perm_mask;
619} 663}
620#endif 664#endif
665
666#if 0 \
667 || ENABLE_FEATURE_FIND_AMIN \
668 || ENABLE_FEATURE_FIND_ATIME \
669 || ENABLE_FEATURE_FIND_CMIN \
670 || ENABLE_FEATURE_FIND_CTIME \
671 || ENABLE_FEATURE_FIND_MMIN \
672 || ENABLE_FEATURE_FIND_MTIME
673static int time_cmp(const struct stat *statbuf, unsigned type_and_char, time_t N_from_user, unsigned unit)
674{
675 time_t ftime, file_age;
676
677 ftime = statbuf->st_mtime;
678# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME
679# if ENABLE_FEATURE_FIND_ATIME
680 if ((type_and_char >> 8) == 'a')
681 ftime = statbuf->st_atime;
682# endif
683# if ENABLE_FEATURE_FIND_CTIME
684 if ((type_and_char >> 8) == 'c')
685 ftime = statbuf->st_ctime;
686# endif
687 type_and_char &= 0xff;
688# endif
689 file_age = time(NULL) - ftime;
690 N_from_user *= unit;
691 switch (type_and_char) {
692 case '+': return file_age >= N_from_user + unit;
693 case '-': return file_age < N_from_user;
694 /* just numeric time */
695 default: return file_age >= N_from_user && file_age < N_from_user + unit;
696 }
697}
698#endif
699
621#if ENABLE_FEATURE_FIND_MTIME 700#if ENABLE_FEATURE_FIND_MTIME
622ACTF(mtime) 701ACTF(mtime)
623{ 702{
624 time_t file_age = time(NULL) - statbuf->st_mtime; 703 return time_cmp(statbuf,
625 time_t mtime_secs = ap->mtime_days * 24*60*60; 704# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME
626 if (ap->mtime_char == '+') 705 (ap->time_type << 8) |
627 return file_age >= mtime_secs + 24*60*60; 706# endif
628 if (ap->mtime_char == '-') 707 ap->mtime_char,
629 return file_age < mtime_secs; 708 ap->mtime_days, 24*60*60);
630 /* just numeric mtime */
631 return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60);
632} 709}
633#endif 710#endif
634#if ENABLE_FEATURE_FIND_MMIN 711#if ENABLE_FEATURE_FIND_MMIN
635ACTF(mmin) 712ACTF(mmin)
636{ 713{
637 time_t file_age = time(NULL) - statbuf->st_mtime; 714 return time_cmp(statbuf,
638 time_t mmin_secs = ap->mmin_mins * 60; 715# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME
639 if (ap->mmin_char == '+') 716 (ap->time_type << 8) |
640 return file_age >= mmin_secs + 60; 717# endif
641 if (ap->mmin_char == '-') 718 ap->mmin_char,
642 return file_age < mmin_secs; 719 ap->mmin_mins, 60);
643 /* just numeric mmin */
644 return file_age >= mmin_secs && file_age < (mmin_secs + 60);
645} 720}
646#endif 721#endif
647#if ENABLE_FEATURE_FIND_NEWER 722#if ENABLE_FEATURE_FIND_NEWER
@@ -1043,7 +1118,11 @@ static action*** parse_params(char **argv)
1043 IF_FEATURE_FIND_TYPE( PARM_type ,) 1118 IF_FEATURE_FIND_TYPE( PARM_type ,)
1044 IF_FEATURE_FIND_PERM( PARM_perm ,) 1119 IF_FEATURE_FIND_PERM( PARM_perm ,)
1045 IF_FEATURE_FIND_MTIME( PARM_mtime ,) 1120 IF_FEATURE_FIND_MTIME( PARM_mtime ,)
1121 IF_FEATURE_FIND_ATIME( PARM_atime ,)
1122 IF_FEATURE_FIND_CTIME( PARM_ctime ,)
1046 IF_FEATURE_FIND_MMIN( PARM_mmin ,) 1123 IF_FEATURE_FIND_MMIN( PARM_mmin ,)
1124 IF_FEATURE_FIND_AMIN( PARM_amin ,)
1125 IF_FEATURE_FIND_CMIN( PARM_cmin ,)
1047 IF_FEATURE_FIND_NEWER( PARM_newer ,) 1126 IF_FEATURE_FIND_NEWER( PARM_newer ,)
1048 IF_FEATURE_FIND_INUM( PARM_inum ,) 1127 IF_FEATURE_FIND_INUM( PARM_inum ,)
1049 IF_FEATURE_FIND_USER( PARM_user ,) 1128 IF_FEATURE_FIND_USER( PARM_user ,)
@@ -1087,7 +1166,11 @@ static action*** parse_params(char **argv)
1087 IF_FEATURE_FIND_TYPE( "-type\0" ) 1166 IF_FEATURE_FIND_TYPE( "-type\0" )
1088 IF_FEATURE_FIND_PERM( "-perm\0" ) 1167 IF_FEATURE_FIND_PERM( "-perm\0" )
1089 IF_FEATURE_FIND_MTIME( "-mtime\0" ) 1168 IF_FEATURE_FIND_MTIME( "-mtime\0" )
1169 IF_FEATURE_FIND_ATIME( "-atime\0" )
1170 IF_FEATURE_FIND_CTIME( "-ctime\0" )
1090 IF_FEATURE_FIND_MMIN( "-mmin\0" ) 1171 IF_FEATURE_FIND_MMIN( "-mmin\0" )
1172 IF_FEATURE_FIND_AMIN( "-amin\0" )
1173 IF_FEATURE_FIND_CMIN( "-cmin\0" )
1091 IF_FEATURE_FIND_NEWER( "-newer\0" ) 1174 IF_FEATURE_FIND_NEWER( "-newer\0" )
1092 IF_FEATURE_FIND_INUM( "-inum\0" ) 1175 IF_FEATURE_FIND_INUM( "-inum\0" )
1093 IF_FEATURE_FIND_USER( "-user\0" ) 1176 IF_FEATURE_FIND_USER( "-user\0" )
@@ -1373,19 +1456,39 @@ static action*** parse_params(char **argv)
1373 } 1456 }
1374#endif 1457#endif
1375#if ENABLE_FEATURE_FIND_MTIME 1458#if ENABLE_FEATURE_FIND_MTIME
1376 else if (parm == PARM_mtime) { 1459 else if (parm == PARM_mtime
1460# if ENABLE_FEATURE_FIND_ATIME
1461 || parm == PARM_atime
1462# endif
1463# if ENABLE_FEATURE_FIND_CTIME
1464 || parm == PARM_ctime
1465# endif
1466 ) {
1377 action_mtime *ap; 1467 action_mtime *ap;
1378 dbg("%d", __LINE__); 1468 dbg("%d", __LINE__);
1379 ap = ALLOC_ACTION(mtime); 1469 ap = ALLOC_ACTION(mtime);
1470# if ENABLE_FEATURE_FIND_AMIN || ENABLE_FEATURE_FIND_CMIN
1471 ap->time_type = arg[1];
1472# endif
1380 ap->mtime_char = arg1[0]; 1473 ap->mtime_char = arg1[0];
1381 ap->mtime_days = xatoul(plus_minus_num(arg1)); 1474 ap->mtime_days = xatoul(plus_minus_num(arg1));
1382 } 1475 }
1383#endif 1476#endif
1384#if ENABLE_FEATURE_FIND_MMIN 1477#if ENABLE_FEATURE_FIND_MMIN
1385 else if (parm == PARM_mmin) { 1478 else if (parm == PARM_mmin
1479# if ENABLE_FEATURE_FIND_AMIN
1480 || parm == PARM_amin
1481# endif
1482# if ENABLE_FEATURE_FIND_CMIN
1483 || parm == PARM_cmin
1484# endif
1485 ) {
1386 action_mmin *ap; 1486 action_mmin *ap;
1387 dbg("%d", __LINE__); 1487 dbg("%d", __LINE__);
1388 ap = ALLOC_ACTION(mmin); 1488 ap = ALLOC_ACTION(mmin);
1489# if ENABLE_FEATURE_FIND_AMIN || ENABLE_FEATURE_FIND_CMIN
1490 ap->time_type = arg[1];
1491# endif
1389 ap->mmin_char = arg1[0]; 1492 ap->mmin_char = arg1[0];
1390 ap->mmin_mins = xatoul(plus_minus_num(arg1)); 1493 ap->mmin_mins = xatoul(plus_minus_num(arg1));
1391 } 1494 }