diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-02-04 16:33:53 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-02-04 16:33:53 -0500 |
commit | d696346689e161ee8a5623182ed65ab119adb203 (patch) | |
tree | 3c55935d75f847a21c82c1ca7e400971f4f12fb2 /eval.c | |
parent | 0a3754f8b66fc50dafeb61711679fc85c1e38038 (diff) | |
download | bfs-d696346689e161ee8a5623182ed65ab119adb203.tar.xz |
Implement -[ac]?newer.
Diffstat (limited to 'eval.c')
-rw-r--r-- | eval.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -1,3 +1,14 @@ +/********************************************************************* + * bfs * + * Copyright (C) 2015-2016 Tavian Barnes <tavianator@tavianator.com> * + * * + * This program is free software. It comes without any warranty, to * + * the extent permitted by applicable law. You can redistribute it * + * and/or modify it under the terms of the Do What The Fuck You Want * + * To Public License, Version 2, as published by Sam Hocevar. See * + * the COPYING file or http://www.wtfpl.net/ for more details. * + *********************************************************************/ + #include "bfs.h" #include "bftw.h" #include <dirent.h> @@ -122,6 +133,32 @@ bool eval_acmtime(const struct expr *expr, struct eval_state *state) { } /** + * -[ac]?newer tests. + */ +bool eval_acnewer(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; + } + + return time->tv_sec > expr->reftime.tv_sec + || (time->tv_sec == expr->reftime.tv_sec && time->tv_nsec > expr->reftime.tv_nsec); +} + +/** * -gid test. */ bool eval_gid(const struct expr *expr, struct eval_state *state) { |