Make ./top -d .1234567890m work.
This commit is contained in:
parent
07a3b91920
commit
f80065b3b4
10
lib/xwrap.c
10
lib/xwrap.c
@ -791,20 +791,20 @@ double xstrtod(char *s)
|
|||||||
// parse fractional seconds with optional s/m/h/d suffix
|
// parse fractional seconds with optional s/m/h/d suffix
|
||||||
long xparsetime(char *arg, long zeroes, long *fraction)
|
long xparsetime(char *arg, long zeroes, long *fraction)
|
||||||
{
|
{
|
||||||
long l, fr;
|
long l, fr = 0, mask = 1;
|
||||||
char *end;
|
char *end;
|
||||||
|
|
||||||
if (*arg != '.' && !isdigit(*arg)) error_exit("Not a number '%s'", arg);
|
if (*arg != '.' && !isdigit(*arg)) error_exit("Not a number '%s'", arg);
|
||||||
l = strtoul(arg, &end, 10);
|
l = strtoul(arg, &end, 10);
|
||||||
fr = 0;
|
|
||||||
if (*end == '.') {
|
if (*end == '.') {
|
||||||
end++;
|
end++;
|
||||||
while (zeroes--) {
|
while (zeroes--) {
|
||||||
fr *= 10;
|
fr *= 10;
|
||||||
|
mask *= 10;
|
||||||
if (isdigit(*end)) fr += *end++-'0';
|
if (isdigit(*end)) fr += *end++-'0';
|
||||||
}
|
}
|
||||||
|
while (isdigit(*end)) end++;
|
||||||
}
|
}
|
||||||
if (fraction) *fraction = fr;
|
|
||||||
|
|
||||||
// Parse suffix
|
// Parse suffix
|
||||||
if (*end) {
|
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);
|
if (i == -1 || *(end+1)) error_exit("Unknown suffix '%s'", end);
|
||||||
l *= ismhd[i];
|
l *= ismhd[i];
|
||||||
|
fr *= ismhd[i];
|
||||||
|
l += fr/mask;
|
||||||
|
fr %= mask;
|
||||||
}
|
}
|
||||||
|
if (fraction) *fraction = fr;
|
||||||
|
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user