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 /parse.c | |
parent | 0a3754f8b66fc50dafeb61711679fc85c1e38038 (diff) | |
download | bfs-d696346689e161ee8a5623182ed65ab119adb203.tar.xz |
Implement -[ac]?newer.
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -1,8 +1,23 @@ +/********************************************************************* + * 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 <errno.h> +#include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/types.h> +#include <sys/stat.h> #include <time.h> #include <unistd.h> @@ -320,6 +335,28 @@ static struct expr *parse_acmtime(struct parser_state *state, const char *option } /** + * Parse -[ac]?newer. + */ +static struct expr *parse_acnewer(struct parser_state *state, const char *option, enum timefield field) { + struct expr *expr = parse_test_sdata(state, option, eval_acnewer); + if (!expr) { + return NULL; + } + + struct stat sb; + if (fstatat(AT_FDCWD, expr->sdata, &sb, AT_SYMLINK_NOFOLLOW) != 0) { + print_error(NULL, expr->sdata, errno); + free_expr(expr); + return NULL; + } + + expr->reftime = sb.st_mtim; + expr->timefield = field; + + return expr; +} + +/** * "Parse" -daystart. */ static struct expr *parse_daystart(struct parser_state *state) { @@ -426,10 +463,14 @@ static struct expr *parse_literal(struct parser_state *state) { return parse_acmtime(state, arg, ATIME, MINUTES); } else if (strcmp(arg, "-atime") == 0) { return parse_acmtime(state, arg, ATIME, DAYS); + } else if (strcmp(arg, "-anewer") == 0) { + return parse_acnewer(state, arg, ATIME); } else if (strcmp(arg, "-cmin") == 0) { return parse_acmtime(state, arg, CTIME, MINUTES); } else if (strcmp(arg, "-ctime") == 0) { return parse_acmtime(state, arg, CTIME, DAYS); + } else if (strcmp(arg, "-cnewer") == 0) { + return parse_acnewer(state, arg, CTIME); } else if (strcmp(arg, "-color") == 0) { state->cl->color = true; return new_option(state, arg); @@ -468,6 +509,8 @@ static struct expr *parse_literal(struct parser_state *state) { return parse_acmtime(state, arg, MTIME, DAYS); } else if (strcmp(arg, "-name") == 0) { return parse_test_sdata(state, arg, eval_name); + } else if (strcmp(arg, "-newer") == 0) { + return parse_acnewer(state, arg, MTIME); } else if (strcmp(arg, "-path") == 0 || strcmp(arg, "-wholename") == 0) { return parse_test_sdata(state, arg, eval_path); } else if (strcmp(arg, "-print") == 0) { |