diff options
author | Rob Landley <rob@landley.net> | 2017-07-07 03:51:47 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2017-07-07 03:51:47 -0500 |
commit | a0e2e7d3057a5b7344c13e2349d683a0ca3d3899 (patch) | |
tree | b9427b05af92fa6b3e7288b42b45bf6f445860ab /lib | |
parent | 7450ecd568e94e9bdde01afc3b60dc953a12bdc1 (diff) | |
download | toybox-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.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; |