aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-07-07 03:51:47 -0500
committerRob Landley <rob@landley.net>2017-07-07 03:51:47 -0500
commita0e2e7d3057a5b7344c13e2349d683a0ca3d3899 (patch)
treeb9427b05af92fa6b3e7288b42b45bf6f445860ab /lib
parent7450ecd568e94e9bdde01afc3b60dc953a12bdc1 (diff)
downloadtoybox-a0e2e7d3057a5b7344c13e2349d683a0ca3d3899.tar.gz
Make dd use atolx_range(), and teach atolx_range() about "w" suffix (word, *2).
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 6e88fd25..d011af02 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -290,17 +290,18 @@ long long xstrtol(char *str, char **end, int base)
return l;
}
-// atol() with the kilo/mega/giga/tera/peta/exa extensions.
+// atol() with the kilo/mega/giga/tera/peta/exa extensions, plus word and block.
// (zetta and yotta don't fit in 64 bits.)
long long atolx(char *numstr)
{
- char *c = numstr, *suffixes="cbkmgtpe", *end;
+ char *c = numstr, *suffixes="cwbkmgtpe", *end;
long long val;
val = xstrtol(numstr, &c, 0);
if (c != numstr && *c && (end = strchr(suffixes, tolower(*c)))) {
- int shift = end-suffixes-1;
+ int shift = end-suffixes-2;
+ if (shift==-1) val *= 2;
if (!shift) val *= 512;
else if (shift>0) {
if (toupper(*++c)=='d') while (shift--) val *= 1000;