aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-06-26 15:32:27 -0500
committerRob Landley <rob@landley.net>2017-06-26 15:32:27 -0500
commitf30035e88bad1748e8e5546ef43409862db1d91e (patch)
tree61e7cd6b90a72d735e069e2e2574fe09efb5b5f7
parent279eb227c54edec20ce2dcc6dc1e397ec778a464 (diff)
downloadtoybox-f30035e88bad1748e8e5546ef43409862db1d91e.tar.gz
Most things seem to want the "b" suffix to mean 512 instead of 1.
(According to the git history I added "b" for "od" but the man page says 512 there too.)
-rw-r--r--lib/lib.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/lib.c b/lib/lib.c
index ceb1bc7d..6e88fd25 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -299,11 +299,12 @@ long long atolx(char *numstr)
val = xstrtol(numstr, &c, 0);
if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
- int shift = end-suffixes-2;
+ int shift = end-suffixes-1;
- if (shift >= 0) {
- if (toupper(*++c)=='d') do val *= 1000; while (shift--);
- else val *= 1024LL<<(shift*10);
+ if (!shift) val *= 512;
+ else if (shift>0) {
+ if (toupper(*++c)=='d') while (shift--) val *= 1000;
+ else val *= 1LL<<(shift*10);
}
}
while (isspace(*c)) c++;