make "dd -iseek 0x200" iseek to 512, rather than 0, also improve checking of numbers and include more binary multipliers. Reference: /n/sources/patch/maybe/dd-hex Date: Fri Dec 10 16:57:41 CET 2010 Signed-off-by: quanstro@quanstro.net --- /sys/src/cmd/dd.c Fri Dec 10 16:57:29 2010 +++ /sys/src/cmd/dd.c Fri Dec 10 16:57:27 2010 @@ -341,40 +341,45 @@ return 1; } +static char power[] = "kmgtpezy"; + vlong number(vlong big) { - char *cs; + char *cs, *q, ch; + int c; uvlong n; - cs = string; - n = 0; - while(*cs >= '0' && *cs <= '9') - n = n*10 + *cs++ - '0'; - for(;;) - switch(*cs++) { - - case 'k': - n *= 1024; - continue; - - case 'b': - n *= 512; - continue; - -/* case '*':*/ - case 'x': - string = cs; - n *= number(VBIG); - - case '\0': - if(n > big) { - fprint(2, "dd: argument %llud out of range\n", n); - exits("range"); + n = strtoull(string, &cs, 0); + if(cs == string){ +bad: + fprint(2, "dd: bad number %s\n", string); + exits("badnum"); + } + for(;;){ + switch(ch = *cs++){ + default: + q = strchr(power, ch); + if(q == nil) + goto bad; + for(c = q - power + 1; c--; ) + n *= 1024; + break; + case 'b': + n *= 512; + break; + case 'x': +/* case '*':*/ + string = cs; + n *= number(VBIG); + case '\0': + if(n > big) { + fprint(2, "dd: argument %llud out of range\n", n); + exits("range"); + } + return n; } - return n; } - /* never gets here */ } void --- /sys/man/1/dd Fri Dec 10 16:57:35 2010 +++ /sys/man/1/dd Fri Dec 10 16:57:34 2010 @@ -142,12 +142,20 @@ .fi Where sizes are specified, a number of bytes is expected. -A number may end with -.L k -or +A number may end with a sequence +of +.LR k , +.LR m , +.LR g , +.LR t , +.LR e , +.LR z , +.L y +to specify multiplication by +1KiB, 1MiB, etc., or .LR b to specify multiplication by -1024 or 512 respectively; +512; a pair of numbers may be separated by .L x to indicate a product.