diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2021-03-06 14:06:01 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2021-03-06 14:10:24 -0500 |
commit | feb349458e8ae17ede636716ccfa9d97e63f30b1 (patch) | |
tree | b9dd312a3f6ce3e9f7adaa52ced64f124da1b0c3 /parse.c | |
parent | 863b70d198f62f28581162473a521208dd67879e (diff) | |
download | bfs-feb349458e8ae17ede636716ccfa9d97e63f30b1.tar.xz |
Support -flags on all the BSDs
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 35 |
1 files changed, 9 insertions, 26 deletions
@@ -1163,20 +1163,12 @@ static struct expr *parse_f(struct parser_state *state, int arg1, int arg2) { * Parse -flags FLAGS. */ static struct expr *parse_flags(struct parser_state *state, int arg1, int arg2) { -#if __APPLE__ || __FreeBSD__ struct expr *expr = parse_unary_test(state, eval_flags); if (!expr) { return NULL; } - // strtofflags() takes a non-const char * - char *copy = strdup(expr->sdata); - if (!copy) { - parse_perror(state, "strdup()"); - goto err; - } - - char *flags = copy; + const char *flags = expr->sdata; switch (flags[0]) { case '-': expr->mode_cmp = MODE_ALL; @@ -1191,26 +1183,17 @@ static struct expr *parse_flags(struct parser_state *state, int arg1, int arg2) break; } - unsigned long set, clear; - if (strtofflags(&flags, &set, &clear) != 0) { - parse_error(state, "${blu}%s${rs}: Invalid flags ${bld}%s${rs}.\n", expr->argv[0], flags); - goto err; + if (xstrtofflags(&flags, &expr->set_flags, &expr->clear_flags) != 0) { + if (errno == ENOTSUP) { + parse_error(state, "${blu}%s${rs} is missing platform support.\n", expr->argv[0]); + } else { + parse_error(state, "${blu}%s${rs}: Invalid flags ${bld}%s${rs}.\n", expr->argv[0], flags); + } + free_expr(expr); + return NULL; } - expr->set_flags = set; - expr->clear_flags = clear; - - free(copy); return expr; - -err: - free(copy); - free_expr(expr); - return NULL; -#else // !(__APPLE__ || __FreeBSD) - parse_error(state, "${blu}%s${rs} is missing platform support.\n", state->argv[0]); - return NULL; -#endif } /** |