From a0e2e7d3057a5b7344c13e2349d683a0ca3d3899 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 7 Jul 2017 03:51:47 -0500 Subject: Make dd use atolx_range(), and teach atolx_range() about "w" suffix (word, *2). --- lib/lib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/lib.c') 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; -- cgit v1.2.3