diff options
author | gjb <gjb@FreeBSD.org> | 2016-02-08 12:16:01 +0000 |
---|---|---|
committer | gjb <gjb@FreeBSD.org> | 2016-02-08 12:16:01 +0000 |
commit | a44dc347a772a938a3a1e624b4809e7b74f58feb (patch) | |
tree | 06859f2b48e0d90b7e6715c5a5045b4b24de5822 /bin/dd | |
parent | b0e94739464da6f4e73a5f3e80ec779480d16892 (diff) | |
parent | 2ed1e2991e3970aeffef7be33b91401f0aeca84d (diff) | |
download | FreeBSD-src-a44dc347a772a938a3a1e624b4809e7b74f58feb.zip FreeBSD-src-a44dc347a772a938a3a1e624b4809e7b74f58feb.tar.gz |
MFH
Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'bin/dd')
-rw-r--r-- | bin/dd/args.c | 90 | ||||
-rw-r--r-- | bin/dd/dd.1 | 7 |
2 files changed, 47 insertions, 50 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c index 2f197f8..1cbf3b3 100644 --- a/bin/dd/args.c +++ b/bin/dd/args.c @@ -360,6 +360,46 @@ c_conv(const void *a, const void *b) ((const struct conv *)b)->name)); } +static uintmax_t +postfix_to_mult(const char expr) +{ + uintmax_t mult; + + mult = 0; + switch (expr) { + case 'B': + case 'b': + mult = 512; + break; + case 'K': + case 'k': + mult = 1 << 10; + break; + case 'M': + case 'm': + mult = 1 << 20; + break; + case 'G': + case 'g': + mult = 1 << 30; + break; + case 'T': + case 't': + mult = (uintmax_t)1 << 40; + break; + case 'P': + case 'p': + mult = (uintmax_t)1 << 50; + break; + case 'W': + case 'w': + mult = sizeof(int); + break; + } + + return (mult); +} + /* * Convert an expression of the following forms to a uintmax_t. * 1) A positive decimal number. @@ -386,31 +426,7 @@ get_num(const char *val) if (expr == val) /* No valid digits. */ errx(1, "%s: illegal numeric value", oper); - mult = 0; - switch (*expr) { - case 'B': - case 'b': - mult = 512; - break; - case 'K': - case 'k': - mult = 1 << 10; - break; - case 'M': - case 'm': - mult = 1 << 20; - break; - case 'G': - case 'g': - mult = 1 << 30; - break; - case 'W': - case 'w': - mult = sizeof(int); - break; - default: - ; - } + mult = postfix_to_mult(*expr); if (mult != 0) { prevnum = num; @@ -460,29 +476,7 @@ get_off_t(const char *val) if (expr == val) /* No valid digits. */ errx(1, "%s: illegal numeric value", oper); - mult = 0; - switch (*expr) { - case 'B': - case 'b': - mult = 512; - break; - case 'K': - case 'k': - mult = 1 << 10; - break; - case 'M': - case 'm': - mult = 1 << 20; - break; - case 'G': - case 'g': - mult = 1 << 30; - break; - case 'W': - case 'w': - mult = sizeof(int); - break; - } + mult = postfix_to_mult(*expr); if (mult != 0) { prevnum = num; diff --git a/bin/dd/dd.1 b/bin/dd/dd.1 index 0908642..4047cdc 100644 --- a/bin/dd/dd.1 +++ b/bin/dd/dd.1 @@ -32,7 +32,7 @@ .\" @(#)dd.1 8.2 (Berkeley) 1/13/94 .\" $FreeBSD$ .\" -.Dd August 28, 2014 +.Dd February 4, 2016 .Dt DD 1 .Os .Sh NAME @@ -332,10 +332,13 @@ If the number ends with a .Dq Li k , .Dq Li m , .Dq Li g , +.Dq Li t , +.Dq Li p , or .Dq Li w , the -number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G) +number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G), +1099511627776 (1T), 1125899906842624 (1P) or the number of bytes in an integer, respectively. Two or more numbers may be separated by an .Dq Li x |