summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2014-03-24 21:42:41 +0000
committertedu <tedu@openbsd.org>2014-03-24 21:42:41 +0000
commit3058619e929b39c2bf8fd10e7138fa64e8960c51 (patch)
tree490b233044b417b85eb3e3aea6c5d0026390b73a
parentBail out from md_prep_disklabel() with `return', not `exit'. (diff)
downloadwireguard-openbsd-3058619e929b39c2bf8fd10e7138fa64e8960c51.tar.xz
wireguard-openbsd-3058619e929b39c2bf8fd10e7138fa64e8960c51.zip
support gigabytes. also update some comments and make goto label nicer.
ok deraadt jmc
-rw-r--r--bin/dd/args.c68
-rw-r--r--bin/dd/dd.114
2 files changed, 50 insertions, 32 deletions
diff --git a/bin/dd/args.c b/bin/dd/args.c
index 730e71fee38..5331586be27 100644
--- a/bin/dd/args.c
+++ b/bin/dd/args.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: args.c,v 1.22 2014/02/12 01:18:36 bluhm Exp $ */
+/* $OpenBSD: args.c,v 1.23 2014/03/24 21:42:41 tedu Exp $ */
/* $NetBSD: args.c,v 1.7 1996/03/01 01:18:58 jtc Exp $ */
/*-
@@ -312,13 +312,12 @@ f_conv(char *arg)
/*
* Convert an expression of the following forms to a size_t
- * 1) A positive decimal number.
- * 2) A positive decimal number followed by a b (mult by 512).
- * 3) A positive decimal number followed by a k (mult by 1024).
- * 4) A positive decimal number followed by a m (mult by 1048576).
- * 5) A positive decimal number followed by a w (mult by sizeof int)
- * 6) Two or more positive decimal numbers (with/without k,b or w).
- * separated by x (also * for backwards compatibility), specifying
+ * 1) A positive decimal number, optionally followed by
+ * b - multiply by 512.
+ * k, m or g - multiply by 1024 each.
+ * w - multiply by sizeof int
+ * 2) Two or more of the above, separated by x
+ * (or * for backwards compatibility), specifying
* the product of the indicated values.
*/
static size_t
@@ -341,18 +340,24 @@ get_bsz(char *val)
goto erange;
++expr;
break;
- case 'k':
- case 'K':
+ case 'g':
+ case 'G':
t = num;
num *= 1024;
if (t > num)
goto erange;
- ++expr;
- break;
+ /* fallthrough */
case 'm':
case 'M':
t = num;
- num *= 1048576;
+ num *= 1024;
+ if (t > num)
+ goto erange;
+ /* fallthrough */
+ case 'k':
+ case 'K':
+ t = num;
+ num *= 1024;
if (t > num)
goto erange;
++expr;
@@ -374,23 +379,24 @@ get_bsz(char *val)
t = num;
num *= get_bsz(expr + 1);
if (t > num)
-erange: errx(1, "%s: %s", oper, strerror(ERANGE));
+ goto erange;
break;
default:
errx(1, "%s: illegal numeric value", oper);
}
return (num);
+erange:
+ errx(1, "%s: %s", oper, strerror(ERANGE));
}
/*
* Convert an expression of the following forms to an off_t
- * 1) A positive decimal number.
- * 2) A positive decimal number followed by a b (mult by 512).
- * 3) A positive decimal number followed by a k (mult by 1024).
- * 4) A positive decimal number followed by a m (mult by 1048576).
- * 5) A positive decimal number followed by a w (mult by sizeof int)
- * 6) Two or more positive decimal numbers (with/without k,b or w).
- * separated by x (also * for backwards compatibility), specifying
+ * 1) A positive decimal number, optionally followed by
+ * b - multiply by 512.
+ * k, m or g - multiply by 1024 each.
+ * w - multiply by sizeof int
+ * 2) Two or more of the above, separated by x
+ * (or * for backwards compatibility), specifying
* the product of the indicated values.
*/
static off_t
@@ -413,18 +419,24 @@ get_off(char *val)
goto erange;
++expr;
break;
- case 'k':
- case 'K':
+ case 'g':
+ case 'G':
t = num;
num *= 1024;
if (t > num)
goto erange;
- ++expr;
- break;
+ /* fallthrough */
case 'm':
case 'M':
t = num;
- num *= 1048576;
+ num *= 1024;
+ if (t > num)
+ goto erange;
+ /* fallthrough */
+ case 'k':
+ case 'K':
+ t = num;
+ num *= 1024;
if (t > num)
goto erange;
++expr;
@@ -446,10 +458,12 @@ get_off(char *val)
t = num;
num *= get_off(expr + 1);
if (t > num)
-erange: errx(1, "%s: %s", oper, strerror(ERANGE));
+ goto erange;
break;
default:
errx(1, "%s: illegal numeric value", oper);
}
return (num);
+erange:
+ errx(1, "%s: %s", oper, strerror(ERANGE));
}
diff --git a/bin/dd/dd.1 b/bin/dd/dd.1
index 10cfcc25498..6b69a884818 100644
--- a/bin/dd/dd.1
+++ b/bin/dd/dd.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: dd.1,v 1.29 2014/02/14 17:27:58 schwarze Exp $
+.\" $OpenBSD: dd.1,v 1.30 2014/03/24 21:42:41 tedu Exp $
.\" $NetBSD: dd.1,v 1.5 1995/03/21 09:04:04 cgd Exp $
.\"
.\" Copyright (c) 1990, 1993
@@ -33,7 +33,7 @@
.\"
.\" @(#)dd.1 8.2 (Berkeley) 1/13/94
.\"
-.Dd $Mdocdate: February 14 2014 $
+.Dd $Mdocdate: March 24 2014 $
.Dt DD 1
.Os
.Sh NAME
@@ -305,11 +305,13 @@ or
.Sq m
or
.Sq M ,
+.Sq g
+or
+.Sq G ,
or
.Sq w ,
-the number
-is multiplied by 512, 1024 (1K), 1048576 (1M), or the number of bytes
-in an integer, respectively.
+the number is multiplied by 512, 1024 (1K), 1048576 (1M), 1073741824 (1G),
+or the number of bytes in an integer, respectively.
Two or more numbers may be separated by an
.Sq x
to indicate a product.
@@ -405,6 +407,8 @@ the size multipliers
.Sq K ,
.Sq m ,
.Sq M ,
+.Sq g ,
+.Sq G ,
and
.Sq w ,
and