summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2017-11-05 12:03:31 -0500
committerTavian Barnes <tavianator@tavianator.com>2017-11-05 12:04:17 -0500
commit6e9f52c9a8d51cac7db3b62e799fc32072c86443 (patch)
tree2cf2e0acb149421e710ea6b285fdbe7b69d516ba /eval.c
parent7f8bacca4c2b1d35bb65ddf8cbf70fadf1adf66e (diff)
downloadbfs-6e9f52c9a8d51cac7db3b62e799fc32072c86443.tar.xz
Add support for file birth/creation times on platforms that have it
Fixes #19
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/eval.c b/eval.c
index 62dbf55..fe89225 100644
--- a/eval.c
+++ b/eval.c
@@ -135,15 +135,15 @@ bool eval_access(const struct expr *expr, struct eval_state *state) {
}
/**
- * -[acm]{min,time} tests.
+ * -[aBcm]?newer tests.
*/
-bool eval_acmtime(const struct expr *expr, struct eval_state *state) {
+bool eval_newer(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
}
- const struct timespec *time = NULL;
+ const struct timespec *time;
switch (expr->time_field) {
case ATIME:
time = &statbuf->st_atim;
@@ -154,32 +154,32 @@ bool eval_acmtime(const struct expr *expr, struct eval_state *state) {
case MTIME:
time = &statbuf->st_mtim;
break;
- }
- assert(time);
- time_t diff = timespec_diff(&expr->reftime, time);
- switch (expr->time_unit) {
- case MINUTES:
- diff /= 60;
- break;
- case DAYS:
- diff /= 60*60*24;
+#if BFS_HAVE_ST_BIRTHTIM
+ case BTIME:
+ time = &statbuf->st_birthtim;
break;
+#endif
+
+ default:
+ assert(false);
+ return false;
}
- return expr_cmp(expr, diff);
+ return time->tv_sec > expr->reftime.tv_sec
+ || (time->tv_sec == expr->reftime.tv_sec && time->tv_nsec > expr->reftime.tv_nsec);
}
/**
- * -[ac]?newer tests.
+ * -[aBcm]{min,time} tests.
*/
-bool eval_acnewer(const struct expr *expr, struct eval_state *state) {
+bool eval_time(const struct expr *expr, struct eval_state *state) {
const struct stat *statbuf = fill_statbuf(state);
if (!statbuf) {
return false;
}
- const struct timespec *time = NULL;
+ const struct timespec *time;
switch (expr->time_field) {
case ATIME:
time = &statbuf->st_atim;
@@ -190,11 +190,29 @@ bool eval_acnewer(const struct expr *expr, struct eval_state *state) {
case MTIME:
time = &statbuf->st_mtim;
break;
+
+#if BFS_HAVE_ST_BIRTHTIM
+ case BTIME:
+ time = &statbuf->st_birthtim;
+ break;
+#endif
+
+ default:
+ assert(false);
+ return false;
}
- assert(time);
- return time->tv_sec > expr->reftime.tv_sec
- || (time->tv_sec == expr->reftime.tv_sec && time->tv_nsec > expr->reftime.tv_nsec);
+ time_t diff = timespec_diff(&expr->reftime, time);
+ switch (expr->time_unit) {
+ case MINUTES:
+ diff /= 60;
+ break;
+ case DAYS:
+ diff /= 60*60*24;
+ break;
+ }
+
+ return expr_cmp(expr, diff);
}
/**