diff options
-rw-r--r-- | findutils/find.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/findutils/find.c b/findutils/find.c index 6d55db4e9..f557bb762 100644 --- a/findutils/find.c +++ b/findutils/find.c | |||
@@ -618,30 +618,34 @@ ACTF(perm) | |||
618 | return (statbuf->st_mode & 07777) == ap->perm_mask; | 618 | return (statbuf->st_mode & 07777) == ap->perm_mask; |
619 | } | 619 | } |
620 | #endif | 620 | #endif |
621 | |||
622 | #if \ | ||
623 | ENABLE_FEATURE_FIND_MMIN || \ | ||
624 | ENABLE_FEATURE_FIND_MTIME | ||
625 | static int time_cmp(time_t ftime, char time_char, time_t secs, time_t delta) | ||
626 | { | ||
627 | time_t file_age = time(NULL) - ftime; | ||
628 | switch (time_char) { | ||
629 | case '+': return file_age >= secs + delta; | ||
630 | case '-': return file_age < secs; | ||
631 | /* just numeric time */ | ||
632 | default: return file_age >= secs && file_age < secs + delta; | ||
633 | } | ||
634 | } | ||
635 | #endif | ||
636 | |||
621 | #if ENABLE_FEATURE_FIND_MTIME | 637 | #if ENABLE_FEATURE_FIND_MTIME |
622 | ACTF(mtime) | 638 | ACTF(mtime) |
623 | { | 639 | { |
624 | time_t file_age = time(NULL) - statbuf->st_mtime; | 640 | return time_cmp(statbuf->st_mtime, ap->mtime_char, |
625 | time_t mtime_secs = ap->mtime_days * 24*60*60; | 641 | ap->mtime_days * 24*60*60, 24*60*60); |
626 | if (ap->mtime_char == '+') | ||
627 | return file_age >= mtime_secs + 24*60*60; | ||
628 | if (ap->mtime_char == '-') | ||
629 | return file_age < mtime_secs; | ||
630 | /* just numeric mtime */ | ||
631 | return file_age >= mtime_secs && file_age < (mtime_secs + 24*60*60); | ||
632 | } | 642 | } |
633 | #endif | 643 | #endif |
634 | #if ENABLE_FEATURE_FIND_MMIN | 644 | #if ENABLE_FEATURE_FIND_MMIN |
635 | ACTF(mmin) | 645 | ACTF(mmin) |
636 | { | 646 | { |
637 | time_t file_age = time(NULL) - statbuf->st_mtime; | 647 | return time_cmp(statbuf->st_mtime, ap->mmin_char, |
638 | time_t mmin_secs = ap->mmin_mins * 60; | 648 | ap->mmin_mins * 60, 60); |
639 | if (ap->mmin_char == '+') | ||
640 | return file_age >= mmin_secs + 60; | ||
641 | if (ap->mmin_char == '-') | ||
642 | return file_age < mmin_secs; | ||
643 | /* just numeric mmin */ | ||
644 | return file_age >= mmin_secs && file_age < (mmin_secs + 60); | ||
645 | } | 649 | } |
646 | #endif | 650 | #endif |
647 | #if ENABLE_FEATURE_FIND_NEWER | 651 | #if ENABLE_FEATURE_FIND_NEWER |