diff options
author | Rob Landley <rob@landley.net> | 2018-10-21 21:48:29 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2018-10-21 21:48:29 -0500 |
commit | f80065b3b45192ccbca5c15bf8015b709876ed43 (patch) | |
tree | 967d6d935857819f367f97fe89d0be0004d0aeec | |
parent | 07a3b9192001369c7bf74cd4f096dc49703b24e9 (diff) | |
download | toybox-f80065b3b45192ccbca5c15bf8015b709876ed43.tar.gz |
Make ./top -d .1234567890m work.
-rw-r--r-- | lib/xwrap.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c index fba262b9..2027069d 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -791,20 +791,20 @@ double xstrtod(char *s) // parse fractional seconds with optional s/m/h/d suffix long xparsetime(char *arg, long zeroes, long *fraction) { - long l, fr; + long l, fr = 0, mask = 1; char *end; if (*arg != '.' && !isdigit(*arg)) error_exit("Not a number '%s'", arg); l = strtoul(arg, &end, 10); - fr = 0; if (*end == '.') { end++; while (zeroes--) { fr *= 10; + mask *= 10; if (isdigit(*end)) fr += *end++-'0'; } + while (isdigit(*end)) end++; } - if (fraction) *fraction = fr; // Parse suffix if (*end) { @@ -812,7 +812,11 @@ long xparsetime(char *arg, long zeroes, long *fraction) if (i == -1 || *(end+1)) error_exit("Unknown suffix '%s'", end); l *= ismhd[i]; + fr *= ismhd[i]; + l += fr/mask; + fr %= mask; } + if (fraction) *fraction = fr; return l; } |