aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2024-04-05 12:18:56 -0500
committerRob Landley <rob@landley.net>2024-04-05 12:18:56 -0500
commit2b867151f7ec7029791dae2b088c6243bf15e86d (patch)
tree6c4843c5d4f9e98dc227fd62fa0c77849afe407b
parent59b041d14aec3bc9f0b340efdcccd739ab8c7758 (diff)
downloadtoybox-2b867151f7ec7029791dae2b088c6243bf15e86d.tar.gz
Enforce min/max for % input type (time in seconds w/millisecond granularity).
-rw-r--r--lib/args.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/args.c b/lib/args.c
index c5ba4505..dd57874e 100644
--- a/lib/args.c
+++ b/lib/args.c
@@ -206,12 +206,13 @@ static void gotflag(struct getoptflagstate *gof, struct opts *opt, int longopt)
while (*list) list=&((*list)->next);
*list = xzalloc(sizeof(struct arg_list));
(*list)->arg = arg;
- } else if (type == '#' || type == '-') {
- long long l = atolx(arg);
+ } else if (type == '#' || type == '-' || type == '%') {
+ long long l = (type == '%') ? xparsemillitime(arg) : atolx(arg);
+ arg = (type == '%') ? "ms" : "";
if (type == '-' && !ispunct(*arg)) l*=-1;
- if (l < opt->val[0].l) help_exit("-%c < %ld", opt->c, opt->val[0].l);
- if (l > opt->val[1].l) help_exit("-%c > %ld", opt->c, opt->val[1].l);
+ if (l < opt->val[0].l) help_exit("-%c < %ld%s", opt->c, opt->val[0].l, arg);
+ if (l > opt->val[1].l) help_exit("-%c > %ld%s", opt->c, opt->val[1].l, arg);
*(opt->arg) = l;
} else if (CFG_TOYBOX_FLOAT && type == '.') {
@@ -222,7 +223,7 @@ static void gotflag(struct getoptflagstate *gof, struct opts *opt, int longopt)
help_exit("-%c < %lf", opt->c, (double)opt->val[0].f);
if (opt->val[1].l != LONG_MAX && *f > opt->val[1].f)
help_exit("-%c > %lf", opt->c, (double)opt->val[1].f);
- } else if (type=='%') *(opt->arg) = xparsemillitime(arg);
+ }
}
// Parse this command's options string into struct getoptflagstate, which