From eee28e7b5851a6eb16f7969393d8c6292b1f8754 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 3 May 2018 15:09:14 -0700 Subject: Support fractional seconds (and other time units) in `top -d`. LTP uses `top -d 0.1`, which isn't convincingly useful, but general support for other time units might be useful, and switching to xparsetime addresses both at once. Also fix 3169d948c049664bcf7216d4c4ae751881099d3e where I mistakenly treated `rev` and `toys.optflags&FLAG_b` as interchangeable. (Without this second fix, `top -b` looks fine but `top` is broken!) Also fix xparsetime to reject input such as "monkey" or "1monkey". --- lib/xwrap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lib/xwrap.c') diff --git a/lib/xwrap.c b/lib/xwrap.c index 54985db3..26383c92 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -792,15 +792,19 @@ long xparsetime(char *arg, long units, long *fraction) { double d; long l; + char *end; + + if (CFG_TOYBOX_FLOAT) d = strtod(arg, &end); + else l = strtoul(arg, &end, 10); - if (CFG_TOYBOX_FLOAT) d = strtod(arg, &arg); - else l = strtoul(arg, &arg, 10); + if (end == arg) error_exit("Not a number '%s'", arg); + arg = end; // Parse suffix if (*arg) { int ismhd[]={1,60,3600,86400}, i = stridx("smhd", *arg); - if (i == -1) error_exit("Unknown suffix '%c'", *arg); + if (i == -1 || *(arg+1)) error_exit("Unknown suffix '%s'", arg); if (CFG_TOYBOX_FLOAT) d *= ismhd[i]; else l *= ismhd[i]; } -- cgit v1.2.3