summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-02-04 13:48:01 -0500
committerTavian Barnes <tavianator@tavianator.com>2016-02-04 13:48:01 -0500
commitbff3576bedf7337d2cd7bd8f106519b38d128535 (patch)
treef89648bc8fde78d30fdd49f56510ba2215b8df54 /eval.c
parent6352b151dc6436ee53fa3e32bd02f0e5b5e1e317 (diff)
downloadbfs-bff3576bedf7337d2cd7bd8f106519b38d128535.tar.xz
Refactor how -[acm]{min,time} are handled.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c101
1 files changed, 22 insertions, 79 deletions
diff --git a/eval.c b/eval.c
index 7de11bf..258857c 100644
--- a/eval.c
+++ b/eval.c
@@ -49,20 +49,6 @@ static time_t timespec_diff(const struct timespec *lhs, const struct timespec *r
}
/**
- * Convert a second count to minutes.
- */
-static time_t to_minutes(time_t seconds) {
- return seconds/60;
-}
-
-/**
- * Convert a second count to days.
- */
-static time_t to_days(time_t seconds) {
- return seconds/60/60/24;
-}
-
-/**
* Perform a comparison.
*/
static bool do_cmp(const struct expr *expr, int n) {
@@ -101,81 +87,38 @@ bool eval_access(const struct expr *expr, struct eval_state *state) {
}
/**
- * -amin test.
+ * -[acm]{min,time} tests.
*/
-bool eval_amin(const struct expr *expr, struct eval_state *state) {
+bool eval_acmtime(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
}
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_atim);
- return do_cmp(expr, to_minutes(diff));
-}
-
-/**
- * -atime test.
- */
-bool eval_atime(const struct expr *expr, struct eval_state *state) {
- const struct stat *statbuf = fill_statbuf(state);
- if (!statbuf) {
- return false;
- }
-
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_atim);
- return do_cmp(expr, to_days(diff));
-}
-
-/**
- * -cmin test.
- */
-bool eval_cmin(const struct expr *expr, struct eval_state *state) {
- const struct stat *statbuf = fill_statbuf(state);
- if (!statbuf) {
- return false;
+ const struct timespec *time;
+ switch (expr->timefield) {
+ case ATIME:
+ time = &statbuf->st_atim;
+ break;
+ case CTIME:
+ time = &statbuf->st_ctim;
+ break;
+ case MTIME:
+ time = &statbuf->st_mtim;
+ break;
}
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_ctim);
- return do_cmp(expr, to_minutes(diff));
-}
-
-/**
- * -ctime test.
- */
-bool eval_ctime(const struct expr *expr, struct eval_state *state) {
- const struct stat *statbuf = fill_statbuf(state);
- if (!statbuf) {
- return false;
- }
-
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_ctim);
- return do_cmp(expr, to_days(diff));
-}
-
-/**
- * -mmin test.
- */
-bool eval_mmin(const struct expr *expr, struct eval_state *state) {
- const struct stat *statbuf = fill_statbuf(state);
- if (!statbuf) {
- return false;
- }
-
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_mtim);
- return do_cmp(expr, to_minutes(diff));
-}
-
-/**
- * -mtime test.
- */
-bool eval_mtime(const struct expr *expr, struct eval_state *state) {
- const struct stat *statbuf = fill_statbuf(state);
- if (!statbuf) {
- return false;
+ time_t diff = timespec_diff(&state->cl->now, time);
+ switch (expr->timeunit) {
+ case MINUTES:
+ diff /= 60;
+ break;
+ case DAYS:
+ diff /= 60*60*24;
+ break;
}
- time_t diff = timespec_diff(&state->cl->now, &statbuf->st_mtim);
- return do_cmp(expr, to_days(diff));
+ return do_cmp(expr, diff);
}
/**