aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-10-10 15:18:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-10 15:18:12 +0200
commitd8e39b5917a5dc9c11ecf5714b8c2e1037a9838d (patch)
treedc1291cfffb1408071dc2aa9f8eff978d2dab670
parentd3dbf4ac05e969b6648faea282df6dec7051e315 (diff)
downloadbusybox-w32-d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d.tar.gz
busybox-w32-d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d.tar.bz2
busybox-w32-d8e39b5917a5dc9c11ecf5714b8c2e1037a9838d.zip
find: code shrink -{m,a,c}{time,min}
function old new delta time_cmp - 181 +181 func_mmin 171 31 -140 func_mtime 180 34 -146 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 181/-286) Total: -105 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--findutils/find.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/findutils/find.c b/findutils/find.c
index 9feb44b64..fdc5c152d 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -440,8 +440,8 @@ IF_FEATURE_FIND_PRINT0( ACTS(print0))
440IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;)) 440IF_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
441IF_FEATURE_FIND_EXECUTABLE(ACTS(executable)) 441IF_FEATURE_FIND_EXECUTABLE(ACTS(executable))
442IF_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;))
443IF_FEATURE_FIND_MTIME( ACTS(mtime, char time_type; char mtime_char; unsigned mtime_days;)) 443IF_FEATURE_FIND_MTIME( ACTS(mtime, unsigned char time_type; unsigned char mtime_char; unsigned mtime_days;))
444IF_FEATURE_FIND_MMIN( ACTS(mmin, char time_type; char mmin_char; unsigned mmin_mins;)) 444IF_FEATURE_FIND_MMIN( ACTS(mmin, unsigned char time_type; unsigned char mmin_char; unsigned mmin_mins;))
445IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;)) 445IF_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
446IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;)) 446IF_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
447IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;)) 447IF_FEATURE_FIND_USER( ACTS(user, uid_t uid;))
@@ -670,14 +670,29 @@ ACTF(perm)
670 || ENABLE_FEATURE_FIND_CTIME \ 670 || ENABLE_FEATURE_FIND_CTIME \
671 || ENABLE_FEATURE_FIND_MMIN \ 671 || ENABLE_FEATURE_FIND_MMIN \
672 || ENABLE_FEATURE_FIND_MTIME 672 || ENABLE_FEATURE_FIND_MTIME
673static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) 673static int time_cmp(const struct stat *statbuf, unsigned type_and_char, time_t N_from_user, unsigned unit)
674{ 674{
675 time_t file_age = time(NULL) - ftime; 675 time_t ftime, file_age;
676 switch (time_char) { 676
677 case '+': return file_age >= secs + delta; 677 ftime = statbuf->st_mtime;
678 case '-': return file_age < secs; 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;
679 /* just numeric time */ 694 /* just numeric time */
680 default: return file_age >= secs && file_age < secs + delta; 695 default: return file_age >= N_from_user && file_age < N_from_user + unit;
681 } 696 }
682} 697}
683#endif 698#endif
@@ -685,33 +700,23 @@ static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta)
685#if ENABLE_FEATURE_FIND_MTIME 700#if ENABLE_FEATURE_FIND_MTIME
686ACTF(mtime) 701ACTF(mtime)
687{ 702{
688 time_t t = statbuf->st_mtime; 703 return time_cmp(statbuf,
689# if ENABLE_FEATURE_FIND_ATIME 704# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME
690 if (ap->time_type == 'a') 705 (ap->time_type << 8) |
691 t = statbuf->st_atime;
692# endif 706# endif
693# if ENABLE_FEATURE_FIND_CTIME 707 ap->mtime_char,
694 if (ap->time_type == 'c') 708 ap->mtime_days, 24*60*60);
695 t = statbuf->st_ctime;
696# endif
697 return time_cmp(t, ap->mtime_char,
698 ap->mtime_days * 24*60*60, 24*60*60);
699} 709}
700#endif 710#endif
701#if ENABLE_FEATURE_FIND_MMIN 711#if ENABLE_FEATURE_FIND_MMIN
702ACTF(mmin) 712ACTF(mmin)
703{ 713{
704 time_t t = statbuf->st_mtime; 714 return time_cmp(statbuf,
705# if ENABLE_FEATURE_FIND_AMIN 715# if ENABLE_FEATURE_FIND_ATIME || ENABLE_FEATURE_FIND_CTIME
706 if (ap->time_type == 'a') 716 (ap->time_type << 8) |
707 t = statbuf->st_atime;
708# endif
709# if ENABLE_FEATURE_FIND_CMIN
710 if (ap->time_type == 'c')
711 t = statbuf->st_ctime;
712# endif 717# endif
713 return time_cmp(t, ap->mmin_char, 718 ap->mmin_char,
714 ap->mmin_mins * 60, 60); 719 ap->mmin_mins, 60);
715} 720}
716#endif 721#endif
717#if ENABLE_FEATURE_FIND_NEWER 722#if ENABLE_FEATURE_FIND_NEWER