changeset 20585:60c9e764baaa

10182 dd: print scaled stats Reviewed by: Andy Fiddaman <af@citrus-it.net> Reviewed by: Adam Števko <adam.stevko@gmail.com> Reviewed by: Marcel Telka <marcel@telka.sk> Reviewed by: Gergő Mihály Doma <domag02@gmail.com> Approved by: Robert Mustacchi <rm@joyent.com>
author Toomas Soome <tsoome@me.com>
date Sun, 06 Jan 2019 10:51:31 +0200
parents 098b1b31b21d
children 3d5baab6151f
files usr/src/cmd/dd/Makefile usr/src/cmd/dd/dd.c
diffstat 2 files changed, 234 insertions(+), 387 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/dd/Makefile	Fri Nov 24 14:37:01 2017 +0200
+++ b/usr/src/cmd/dd/Makefile	Sun Jan 06 10:51:31 2019 +0200
@@ -31,6 +31,7 @@
 CFLAGS += $(CCVERBOSE)
 CERRWARN += -_gcc=-Wno-uninitialized
 CPPFLAGS += -D_FILE_OFFSET_BITS=64
+LDLIBS += -lcmdutils
 
 .KEEP_STATE:
 
--- a/usr/src/cmd/dd/dd.c	Fri Nov 24 14:37:01 2017 +0200
+++ b/usr/src/cmd/dd/dd.c	Sun Jan 06 10:51:31 2019 +0200
@@ -29,7 +29,7 @@
  */
 
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
-/*	  All Rights Reserved  	*/
+/*		All Rights Reserved	*/
 
 /*
  *	convert and copy
@@ -49,6 +49,7 @@
 #include	<sys/time.h>
 #include	<errno.h>
 #include	<strings.h>
+#include	<libcmdutils.h>
 
 /* The BIG parameter is machine dependent.  It should be a long integer	*/
 /* constant that can be used by the number parser to check the validity	*/
@@ -169,7 +170,7 @@
 /* This is an EBCDIC to ASCII conversion table	*/
 /* from a proposed BTL standard April 16, 1979	*/
 
-static unsigned char svr4_etoa [] =
+static unsigned char svr4_etoa[] =
 {
 	0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177,
 	0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017,
@@ -208,7 +209,7 @@
 /* This is an ASCII to EBCDIC conversion table	*/
 /* from a proposed BTL standard April 16, 1979	*/
 
-static unsigned char svr4_atoe [] =
+static unsigned char svr4_atoe[] =
 {
 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
@@ -360,7 +361,7 @@
 
 /* BSD-compatible EBCDIC to ASCII translate table */
 
-static unsigned char	bsd_etoa[] =
+static unsigned char bsd_etoa[] =
 {
 	0000, 0001, 0002, 0003, 0234, 0011, 0206, 0177,
 	0227, 0215, 0216, 0013, 0014, 0015, 0016, 0017,
@@ -398,7 +399,7 @@
 
 /* BSD-compatible ASCII to EBCDIC translate table */
 
-static unsigned char	bsd_atoe[] =
+static unsigned char bsd_atoe[] =
 {
 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
@@ -436,7 +437,7 @@
 
 /* BSD-compatible ASCII to IBM translate table */
 
-static unsigned char	bsd_atoibm[] =
+static unsigned char bsd_atoibm[] =
 {
 	0000, 0001, 0002, 0003, 0067, 0055, 0056, 0057,
 	0026, 0005, 0045, 0013, 0014, 0015, 0016, 0017,
@@ -522,104 +523,82 @@
 
 	/* not getopt()'ed because dd has no options but only operand(s) */
 
-	for (c = optind; c < argc; c++)
-	{
+	for (c = optind; c < argc; c++) {
 		string = argv[c];
-		if (match("ibs="))
-		{
+		if (match("ibs=")) {
 			ibs = (unsigned)number(BIG);
 			continue;
 		}
-		if (match("obs="))
-		{
+		if (match("obs=")) {
 			obs = (unsigned)number(BIG);
 			continue;
 		}
-		if (match("cbs="))
-		{
+		if (match("cbs=")) {
 			cbs = (unsigned)number(BIG);
 			continue;
 		}
-		if (match("bs="))
-		{
+		if (match("bs=")) {
 			bs = (unsigned)number(BIG);
 			continue;
 		}
-		if (match("if="))
-		{
+		if (match("if=")) {
 			ifile = string;
 			continue;
 		}
-		if (match("of="))
-		{
+		if (match("of=")) {
 			ofile = string;
 			continue;
 		}
-		if (match("skip="))
-		{
+		if (match("skip=")) {
 			skip = number(BIG);
 			continue;
 		}
-		if (match("iseek="))
-		{
+		if (match("iseek=")) {
 			iseekn = number(BIG);
 			continue;
 		}
-		if (match("oseek="))
-		{
+		if (match("oseek=")) {
 			oseekn = number(BIG);
 			continue;
 		}
-		if (match("seek="))		/* retained for compatibility */
-		{
+		if (match("seek=")) {		/* retained for compatibility */
 			oseekn = number(BIG);
 			continue;
 		}
-		if (match("ostride="))
-		{
+		if (match("ostride=")) {
 			ostriden = ((off_t)number(BIG)) - 1;
 			continue;
 		}
-		if (match("istride="))
-		{
+		if (match("istride=")) {
 			istriden = ((off_t)number(BIG)) - 1;
 			continue;
 		}
-		if (match("stride="))
-		{
+		if (match("stride=")) {
 			istriden = ostriden = ((off_t)number(BIG)) - 1;
 			continue;
 		}
-		if (match("count="))
-		{
+		if (match("count=")) {
 			count = number(BIG);
 			ecount = B_TRUE;
 			continue;
 		}
-		if (match("files="))
-		{
+		if (match("files=")) {
 			files = (int)number(BIG);
 			continue;
 		}
-		if (match("conv="))
-		{
-			for (;;)
-			{
-				if (match(","))
-				{
+		if (match("conv=")) {
+			for (;;) {
+				if (match(",")) {
 					continue;
 				}
-				if (*string == '\0')
-				{
+				if (*string == '\0') {
 					break;
 				}
-				if (match("block"))
-				{
+				if (match("block")) {
 					conv = BLOCK;
 					continue;
 				}
-				if (match("unblock"))
-				{
+				if (match("unblock")) {
 					conv = UNBLOCK;
 					continue;
 				}
@@ -627,69 +606,57 @@
 				/* ebcdicb, ibmb, and asciib must precede */
 				/* ebcdic, ibm, and ascii in this test */
 
-				if (match("ebcdicb"))
-				{
+				if (match("ebcdicb")) {
 					conv = EBCDIC;
 					trantype = BSDXLATE;
 					continue;
 				}
-				if (match("ibmb"))
-				{
+				if (match("ibmb")) {
 					conv = IBM;
 					trantype = BSDXLATE;
 					continue;
 				}
-				if (match("asciib"))
-				{
+				if (match("asciib")) {
 					conv = ASCII;
 					trantype = BSDXLATE;
 					continue;
 				}
-				if (match("ebcdic"))
-				{
+				if (match("ebcdic")) {
 					conv = EBCDIC;
 					trantype = SVR4XLATE;
 					continue;
 				}
-				if (match("ibm"))
-				{
+				if (match("ibm")) {
 					conv = IBM;
 					trantype = SVR4XLATE;
 					continue;
 				}
-				if (match("ascii"))
-				{
+				if (match("ascii")) {
 					conv = ASCII;
 					trantype = SVR4XLATE;
 					continue;
 				}
-				if (match("lcase"))
-				{
+				if (match("lcase")) {
 					cflag |= LCASE;
 					continue;
 				}
-				if (match("ucase"))
-				{
+				if (match("ucase")) {
 					cflag |= UCASE;
 					continue;
 				}
-				if (match("swab"))
-				{
+				if (match("swab")) {
 					cflag |= SWAB;
 					continue;
 				}
-				if (match("noerror"))
-				{
+				if (match("noerror")) {
 					cflag |= NERR;
 					continue;
 				}
-				if (match("notrunc"))
-				{
+				if (match("notrunc")) {
 					trunc = 0;
 					continue;
 				}
-				if (match("sync"))
-				{
+				if (match("sync")) {
 					cflag |= SYNC;
 					continue;
 				}
@@ -697,25 +664,19 @@
 			}
 			continue;
 		}
-		if (match("oflag="))
-		{
-			for (;;)
-			{
-				if (match(","))
-				{	
+		if (match("oflag=")) {
+			for (;;) {
+				if (match(",")) {
 					continue;
 				}
-				if (*string == '\0')
-				{
+				if (*string == '\0') {
 					break;
 				}
-				if (match("dsync"))
-				{
+				if (match("dsync")) {
 					oflag |= O_DSYNC;
 					continue;
 				}
-				if (match("sync"))
-				{
+				if (match("sync")) {
 					oflag |= O_SYNC;
 					continue;
 				}
@@ -725,43 +686,37 @@
 		}
 		badarg:
 		(void) fprintf(stderr, "dd: %s \"%s\"\n",
-			gettext("bad argument:"), string);
+		    gettext("bad argument:"), string);
 		exit(2);
 	}
 
 	/* Perform consistency checks on options, decode strange conventions */
 
-	if (bs)
-	{
+	if (bs) {
 		ibs = obs = bs;
 	}
-	if ((ibs == 0) || (obs == 0))
-	{
+	if ((ibs == 0) || (obs == 0)) {
 		(void) fprintf(stderr, "dd: %s\n",
-			gettext("buffer sizes cannot be zero"));
+		    gettext("buffer sizes cannot be zero"));
 		exit(2);
 	}
 	if (ostriden == (off_t)-1) {
 		(void) fprintf(stderr, "dd: %s\n",
-			gettext("stride must be greater than zero"));
+		    gettext("stride must be greater than zero"));
 		exit(2);
 	}
 	if (istriden == (off_t)-1) {
 		(void) fprintf(stderr, "dd: %s\n",
-			gettext("stride must be greater than zero"));
+		    gettext("stride must be greater than zero"));
 		exit(2);
 	}
-	if (conv == COPY)
-	{
-		if ((bs == 0) || (cflag&(LCASE|UCASE)))
-		{
+	if (conv == COPY) {
+		if ((bs == 0) || (cflag & (LCASE | UCASE))) {
 			conv = REBLOCK;
 		}
 	}
-	if (cbs == 0)
-	{
-		switch (conv)
-		{
+	if (cbs == 0) {
+		switch (conv) {
 		case BLOCK:
 		case UNBLOCK:
 			conv = REBLOCK;
@@ -783,68 +738,67 @@
 
 	/* Expand options into lower and upper case versions if necessary */
 
-	switch (conv)
-	{
+	switch (conv) {
 	case REBLOCK:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCREBLOCK;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCREBLOCK;
 		break;
 
 	case UNBLOCK:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCUNBLOCK;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCUNBLOCK;
 		break;
 
 	case BLOCK:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCBLOCK;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCBLOCK;
 		break;
 
 	case ASCII:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCASCII;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCASCII;
 		break;
 
 	case NBASCII:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCNBASCII;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCNBASCII;
 		break;
 
 	case EBCDIC:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCEBCDIC;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCEBCDIC;
 		break;
 
 	case NBEBCDIC:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCNBEBCDIC;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCNBEBCDIC;
 		break;
 
 	case IBM:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCIBM;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCIBM;
 		break;
 
 	case NBIBM:
-		if (cflag&LCASE)
+		if (cflag & LCASE)
 			conv = LCNBIBM;
-		else if (cflag&UCASE)
+		else if (cflag & UCASE)
 			conv = UCNBIBM;
 		break;
 	}
@@ -859,18 +813,14 @@
 	/* Open the input file, or duplicate standard input */
 
 	ibf = -1;
-	if (ifile)
-	{
+	if (ifile) {
 		ibf = open(ifile, 0);
-	}
-	else
-	{
+	} else {
 		ifile = "";
-		ibf = dup(0);
+		ibf = dup(STDIN_FILENO);
 	}
 
-	if (ibf == -1)
-	{
+	if (ibf == -1) {
 		(void) fprintf(stderr, "dd: %s: ", ifile);
 		perror("open");
 		exit(2);
@@ -879,17 +829,16 @@
 	/* Open the output file, or duplicate standard output */
 
 	obf = -1;
-	if (ofile)
-	{
-		if (trunc == 0)	/* do not truncate output file */
-			obf = open(ofile, (O_WRONLY|O_CREAT|oflag),
-			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
-		else if (oseekn && (trunc == 1))
-		{
-			obf = open(ofile, O_WRONLY|O_CREAT|oflag,
-			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
-			if (obf == -1)
-			{
+	if (ofile) {
+		if (trunc == 0)	{	/* do not truncate output file */
+			obf = open(ofile, (O_WRONLY | O_CREAT | oflag),
+			    (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
+			    S_IROTH | S_IWOTH));
+		} else if (oseekn && (trunc == 1)) {
+			obf = open(ofile, O_WRONLY | O_CREAT | oflag,
+			    (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
+			    S_IROTH | S_IWOTH));
+			if (obf == -1) {
 				(void) fprintf(stderr, "dd: %s: ", ofile);
 				perror("open");
 				exit(2);
@@ -897,24 +846,21 @@
 			(void) fstat(obf, &file_stat);
 			if (((file_stat.st_mode & S_IFMT) == S_IFREG) &&
 			    (ftruncate(obf, (((off_t)oseekn) * ((off_t)obs)))
-				== -1))
-			{
+			    == -1)) {
 				perror("ftruncate");
 				exit(2);
 			}
+		} else {
+			obf = open(ofile, O_WRONLY | O_CREAT | O_TRUNC | oflag,
+			    (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
+			    S_IROTH | S_IWOTH));
 		}
-		else
-			obf = open(ofile, O_WRONLY|O_CREAT|O_TRUNC|oflag,
-			(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH));
-	}
-	else
-	{
+	} else {
 		ofile = "";
-		obf = dup(1);
+		obf = dup(STDOUT_FILENO);
 	}
 
-	if (obf == -1)
-	{
+	if (obf == -1) {
 		(void) fprintf(stderr, "dd: %s: ", ofile);
 		perror("open");
 		exit(2);
@@ -926,22 +872,21 @@
 
 	/* If no conversions, the input buffer is the output buffer */
 
-	if (conv == COPY)
-	{
+	if (conv == COPY) {
 		obuf = ibuf;
-	}
+	} else {
 
-	/* Expand memory to get an output buffer. Leave enough room at the */
-	/* end to convert a logical record when doing block conversions. */
+		/*
+		 * Expand memory to get an output buffer. Leave enough room
+		 * at the end to convert a logical record when doing block
+		 * conversions.
+		 */
 
-	else
-	{
 		obuf = (unsigned char *)valloc(obs + cbs + 10);
 	}
-	if ((ibuf == (unsigned char *)NULL) || (obuf == (unsigned char *)NULL))
-	{
+	if ((ibuf == NULL) || (obuf == NULL)) {
 		(void) fprintf(stderr,
-			"dd: %s\n", gettext("not enough memory"));
+		    "dd: %s\n", gettext("not enough memory"));
 		exit(2);
 	}
 
@@ -950,8 +895,7 @@
 	 * Also enable it to be queried via SIGINFO and SIGUSR1
 	 */
 
-	if (signal(SIGINT, SIG_IGN) != SIG_IGN)
-	{
+	if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
 		(void) signal(SIGINT, term);
 	}
 
@@ -974,32 +918,22 @@
 
 	/* Skip input blocks */
 
-	while (skip)
-	{
+	while (skip) {
 		ibc = read(ibf, (char *)ibuf, ibs);
-		if (ibc == (unsigned)-1)
-		{
-			if (++nbad > BADLIMIT)
-			{
+		if (ibc == (unsigned)-1) {
+			if (++nbad > BADLIMIT) {
 				(void) fprintf(stderr, "dd: %s\n",
-					gettext("skip failed"));
+				    gettext("skip failed"));
 				exit(2);
-			}
-			else
-			{
+			} else {
 				perror("read");
 			}
-		}
-		else
-		{
-			if (ibc == 0)
-			{
+		} else {
+			if (ibc == 0) {
 				(void) fprintf(stderr, "dd: %s\n",
 				gettext("cannot skip past end-of-file"));
 				exit(3);
-			}
-			else
-			{
+			} else {
 				nbad = 0;
 			}
 		}
@@ -1008,16 +942,14 @@
 
 	/* Seek past input blocks */
 
-	if (iseekn && lseek(ibf, (((off_t)iseekn) * ((off_t)ibs)), 1) == -1)
-	{
+	if (iseekn && lseek(ibf, (((off_t)iseekn) * ((off_t)ibs)), 1) == -1) {
 		perror("lseek");
 		exit(2);
 	}
 
 	/* Seek past output blocks */
 
-	if (oseekn && lseek(obf, (((off_t)oseekn) * ((off_t)obs)), 1) == -1)
-	{
+	if (oseekn && lseek(obf, (((off_t)oseekn) * ((off_t)obs)), 1) == -1) {
 		perror("lseek");
 		exit(2);
 	}
@@ -1035,8 +967,7 @@
 	/* Grab our start time for siginfo purposes */
 	startt = gethrtime();
 
-	for (;;)
-	{
+	for (;;) {
 		if (nstats != 0) {
 			stats();
 			nstats = 0;
@@ -1045,8 +976,7 @@
 		if ((count == 0 && ecount == B_FALSE) || (nifr+nipr < count)) {
 		/* If proceed on error is enabled, zero the input buffer */
 
-			if (cflag&NERR)
-			{
+			if (cflag & NERR) {
 				ip = ibuf + ibs;
 				c = ibs;
 				if (c & 1)	/* if the size is odd, */
@@ -1074,43 +1004,31 @@
 
 			/* Process input errors */
 
-			if (ibc == (unsigned)-1)
-			{
+			if (ibc == (unsigned)-1) {
 				perror("read");
-				if (((cflag&NERR) == 0) || (++nbad > BADLIMIT))
-				{
-					while (obc)
-					{
+				if (((cflag & NERR) == 0) ||
+				    (++nbad > BADLIMIT)) {
+					while (obc) {
 						(void) flsh();
 					}
 					term(2);
-				}
-				else
-				{
+				} else {
 					stats();
 					ibc = ibs; /* assume a full block */
 				}
-			}
-			else
-			{
+			} else {
 				nbad = 0;
 			}
-		}
-
-		/* Record count satisfied, simulate end of file */
-
-		else
-		{
+		} else {
+			/* Record count satisfied, simulate end of file */
 			ibc = 0;
 			files = 1;
 		}
 
 		/* Process end of file */
 
-		if (ibc == 0)
-		{
-			switch (conv)
-			{
+		if (ibc == 0) {
+			switch (conv) {
 			case UNBLOCK:
 			case LCUNBLOCK:
 			case UCUNBLOCK:
@@ -1120,11 +1038,9 @@
 
 				/* Trim trailing blanks from the last line */
 
-				if ((c = cbc) != 0)
-				{
+				if ((c = cbc) != 0) {
 					do {
-						if ((*--op) != ' ')
-						{
+						if ((*--op) != ' ') {
 							op++;
 							break;
 						}
@@ -1135,8 +1051,7 @@
 
 					/* Flush the output buffer if full */
 
-					while (obc >= obs)
-					{
+					while (obc >= obs) {
 						op = flsh();
 					}
 				}
@@ -1154,16 +1069,13 @@
 
 			/* Pad trailing blanks if the last line is short */
 
-				if (cbc)
-				{
+				if (cbc) {
 					obc += c = cbs - cbc;
 					cbc = 0;
-					if (c > 0)
-					{
+					if (c > 0) {
 					/* Use the right kind of blank */
 
-						switch (conv)
-						{
+						switch (conv) {
 						case BLOCK:
 						case LCBLOCK:
 						case UCBLOCK:
@@ -1194,8 +1106,7 @@
 
 				/* Flush the output buffer if full */
 
-				while (obc >= obs)
-				{
+				while (obc >= obs) {
 					op = flsh();
 				}
 				break;
@@ -1203,43 +1114,34 @@
 
 			/* If no more files to read, flush the output buffer */
 
-			if (--files <= 0)
-			{
+			if (--files <= 0) {
 				(void) flsh();
-				if ((close(obf) != 0) || (fclose(stdout) != 0))
-				{
+				if ((close(obf) != 0) ||
+				    (fclose(stdout) != 0)) {
 					perror(gettext("dd: close error"));
 					exit(2);
 				}
 				term(0);	/* successful exit */
-			}
-			else
-			{
+			} else {
 				continue;	/* read the next file */
 			}
-		}
-
-		/* Normal read, check for special cases */
-
-		else if (ibc == ibs)
-		{
+		} else if (ibc == ibs) {
+			/* Normal read, check for special cases */
 			nifr++;		/* count another full input record */
-		}
-		else
-		{
+		} else {
 			nipr++;		/* count a partial input record */
 
 			/* If `sync' enabled, pad nulls */
 
-			if ((cflag&SYNC) && ((cflag&NERR) == 0))
-			{
+			if ((cflag & SYNC) && ((cflag & NERR) == 0)) {
 				c = ibs - ibc;
 				ip = ibuf + ibs;
 				do {
-				if ((conv == BLOCK) || (conv == UNBLOCK))
-					*--ip = ' ';
-				else
-					*--ip = '\0';
+					if ((conv == BLOCK) ||
+					    (conv == UNBLOCK))
+						*--ip = ' ';
+					else
+						*--ip = '\0';
 				} while (--c);
 				ibc = ibs;
 			}
@@ -1247,11 +1149,9 @@
 
 		/* Swap the bytes in the input buffer if necessary */
 
-		if (cflag&SWAB)
-		{
+		if (cflag & SWAB) {
 			ip = ibuf;
-			if (ibc & 1)	/* if the byte count is odd, */
-			{
+			if (ibc & 1) {	/* if the byte count is odd, */
 				ip[ibc] = 0;  /* make it even, pad with zero */
 			}
 			c = ibc >> 1;	/* compute the pair count */
@@ -1265,8 +1165,7 @@
 		/* Select the appropriate conversion loop */
 
 		ip = ibuf;
-		switch (conv)
-		{
+		switch (conv) {
 
 		/* Simple copy: no conversion, preserve the input block size */
 
@@ -1289,16 +1188,13 @@
 		case NBIBM:
 		case LCNBIBM:
 		case UCNBIBM:
-			while ((c = ibc) != 0)
-			{
-				if (c > (obs - obc))
-				{
+			while ((c = ibc) != 0) {
+				if (c > (obs - obc)) {
 					c = obs - obc;
 				}
 				ibc -= c;
 				obc += c;
-				switch (conv)
-				{
+				switch (conv) {
 				case REBLOCK:
 					do {
 						*op++ = *ip++;
@@ -1371,8 +1267,7 @@
 					} while (--c);
 					break;
 				}
-				if (obc >= obs)
-				{
+				if (obc >= obs) {
 					op = flsh();
 				}
 			}
@@ -1386,19 +1281,16 @@
 		case ASCII:
 		case LCASCII:
 		case UCASCII:
-			while ((c = ibc) != 0)
-			{
-				if (c > (cbs - cbc))
-						/* if more than one record, */
-				{
+			while ((c = ibc) != 0) {
+				if (c > (cbs - cbc)) {
+					/* if more than one record, */
 					c = cbs - cbc;
-						/* only copy one record */
+					/* only copy one record */
 				}
 				ibc -= c;
 				cbc += c;
 				obc += c;
-				switch (conv)
-				{
+				switch (conv) {
 				case UNBLOCK:
 					do {
 						*op++ = *ip++;
@@ -1438,12 +1330,10 @@
 
 				/* Trim trailing blanks if the line is full */
 
-				if (cbc == cbs)
-				{
+				if (cbc == cbs) {
 					c = cbs; /* `do - while' is usually */
 					do {		/* faster than `for' */
-						if ((*--op) != ' ')
-						{
+						if ((*--op) != ' ') {
 							op++;
 							break;
 						}
@@ -1454,8 +1344,7 @@
 
 					/* Flush the output buffer if full */
 
-					while (obc >= obs)
-					{
+					while (obc >= obs) {
 						op = flsh();
 					}
 				}
@@ -1473,49 +1362,43 @@
 		case IBM:
 		case LCIBM:
 		case UCIBM:
-			while ((c = ibc) != 0)
-			{
+			while ((c = ibc) != 0) {
 				int nlflag = 0;
 
-			/* We may have to skip to the end of a long line */
+				/*
+				 * We may have to skip to the end of a long
+				 * line.
+				 */
 
-				if (skipf)
-				{
+				if (skipf) {
 					do {
-						if ((ic = *ip++) == '\n')
-						{
+						if ((ic = *ip++) == '\n') {
 							skipf = 0;
 							c--;
 							break;
 						}
 					} while (--c);
-					if ((ibc = c) == 0)
-					{
+					if ((ibc = c) == 0) {
 						continue;
-							/* read another block */
+						/* read another block */
 					}
 				}
 
 				/* If anything left, copy until newline */
 
-				if (c > (cbs - cbc + 1))
-				{
+				if (c > (cbs - cbc + 1)) {
 					c = cbs - cbc + 1;
 				}
 				ibc -= c;
 				cbc += c;
 				obc += c;
 
-				switch (conv)
-				{
+				switch (conv) {
 				case BLOCK:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = ic;
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1524,12 +1407,9 @@
 
 				case LCBLOCK:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = utol[ic];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1538,12 +1418,9 @@
 
 				case UCBLOCK:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = ltou[ic];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1552,12 +1429,9 @@
 
 				case EBCDIC:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = atoe[ic];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1566,12 +1440,9 @@
 
 				case LCEBCDIC:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = atoe[utol[ic]];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1580,12 +1451,9 @@
 
 				case UCEBCDIC:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = atoe[ltou[ic]];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1594,12 +1462,9 @@
 
 				case IBM:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
+						if ((ic = *ip++) != '\n') {
 							*op++ = atoibm[ic];
-						}
-						else
-						{
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1608,12 +1473,10 @@
 
 				case LCIBM:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
-						*op++ = atoibm[utol[ic]];
-						}
-						else
-						{
+						if ((ic = *ip++) != '\n') {
+							*op++ =
+							    atoibm[utol[ic]];
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1622,12 +1485,10 @@
 
 				case UCIBM:
 					do {
-						if ((ic = *ip++) != '\n')
-						{
-						*op++ = atoibm[ltou[ic]];
-						}
-						else
-						{
+						if ((ic = *ip++) != '\n') {
+							*op++ =
+							    atoibm[ltou[ic]];
+						} else {
 							nlflag = 1;
 							break;
 						}
@@ -1638,18 +1499,15 @@
 			/* If newline found, update all the counters and */
 			/* pointers, pad with trailing blanks if necessary */
 
-				if (nlflag)
-				{
+				if (nlflag) {
 					ibc += c - 1;
 					obc += cbs - cbc;
 					c += cbs - cbc;
 					cbc = 0;
-					if (c > 0)
-					{
+					if (c > 0) {
 					/* Use the right kind of blank */
 
-						switch (conv)
-						{
+						switch (conv) {
 						case BLOCK:
 						case LCBLOCK:
 						case UCBLOCK:
@@ -1679,8 +1537,7 @@
 
 			/* If not end of line, this line may be too long */
 
-				else if (cbc > cbs)
-				{
+				else if (cbc > cbs) {
 					skipf = 1; /* note skip in progress */
 					obc--;
 					op--;
@@ -1690,8 +1547,7 @@
 
 				/* Flush the output buffer if full */
 
-				while (obc >= obs)
-				{
+				while (obc >= obs) {
 					op = flsh();
 				}
 			}
@@ -1716,21 +1572,17 @@
 /* ********************************************************************	*/
 
 static int
-match(s)
-char *s;
+match(char *s)
 {
 	char *cs;
 
 	cs = string;
-	while (*cs++ == *s)
-	{
-		if (*s++ == '\0')
-		{
+	while (*cs++ == *s) {
+		if (*s++ == '\0') {
 			goto true;
 		}
 	}
-	if (*s != '\0')
-	{
+	if (*s != '\0') {
 		return (0);
 	}
 
@@ -1756,8 +1608,7 @@
 /* ********************************************************************	*/
 
 static unsigned long long
-number(big)
-long long big;
+number(long long big)
 {
 	char *cs;
 	long long n;
@@ -1765,14 +1616,11 @@
 
 	cs = string;
 	n = 0;
-	while ((*cs >= '0') && (*cs <= '9') && (n <= cut))
-	{
-		n = n*10 + *cs++ - '0';
+	while ((*cs >= '0') && (*cs <= '9') && (n <= cut)) {
+		n = n * 10 + *cs++ - '0';
 	}
-	for (;;)
-	{
-		switch (*cs++)
-		{
+	for (;;) {
+		switch (*cs++) {
 
 		case 'Z':
 			n *= 1024;
@@ -1820,17 +1668,16 @@
 		/* End of string, check for a valid number */
 
 		case '\0':
-			if ((n > big) || (n < 0))
-			{
+			if ((n > big) || (n < 0)) {
 				(void) fprintf(stderr, "dd: %s \"%llu\"\n",
-					gettext("argument out of range:"), n);
+				    gettext("argument out of range:"), n);
 				exit(2);
 			}
 			return (n);
 
 		default:
 			(void) fprintf(stderr, "dd: %s \"%s\"\n",
-				gettext("bad numeric argument:"), string);
+			    gettext("bad numeric argument:"), string);
 			exit(2);
 		}
 	} /* never gets here */
@@ -1848,32 +1695,30 @@
 /*									*/
 /* ********************************************************************	*/
 
-static unsigned char
-*flsh()
+static unsigned char *
+flsh(void)
 {
 	unsigned char *op, *cp;
 	int bc;
 	unsigned int oc;
 
-	if (obc)			/* don't flush if the buffer is empty */
-	{
+	if (obc) {			/* don't flush if the buffer is empty */
 		if (obc >= obs) {
 			oc = obs;
 			nofr++;		/* count a full output buffer */
-		}
-		else
-		{
+		} else {
 			oc = obc;
 			nopr++;		/* count a partial output buffer */
 		}
 		bc = write(obf, (char *)obuf, oc);
 		if (bc != oc) {
-			if (bc < 0)
+			if (bc < 0) {
 				perror("write");
-			else
-			(void) fprintf(stderr,
-				gettext("dd: unexpected short write, "
-				"wrote %d bytes, expected %d\n"), bc, oc);
+			} else {
+				(void) fprintf(stderr,
+				    gettext("dd: unexpected short write, "
+				    "wrote %d bytes, expected %d\n"), bc, oc);
+			}
 			term(2);
 		}
 
@@ -1913,8 +1758,7 @@
 /* ********************************************************************	*/
 
 static void
-term(c)
-int c;
+term(int c)
 {
 	stats();
 	exit(c);
@@ -1925,23 +1769,24 @@
 /* Write record statistics onto standard error				*/
 /*									*/
 /* Args:	none							*/
-/* Global args:	nifr, nipr, nofr, nopr, ntrunc				*/
+/* Global args:	nifr, nipr, nofr, nopr, ntrunc, obytes			*/
 /*									*/
 /* Return:	void							*/
 /*									*/
 /* ********************************************************************	*/
 
 static void
-stats()
+stats(void)
 {
 	hrtime_t delta = gethrtime() - startt;
 	double secs = delta * 1e-9;
+	char nnum[NN_NUMBUF_SZ];
 
 	(void) fprintf(stderr, gettext("%llu+%llu records in\n"), nifr, nipr);
 	(void) fprintf(stderr, gettext("%llu+%llu records out\n"), nofr, nopr);
 	if (ntrunc) {
 		(void) fprintf(stderr,
-			gettext("%llu truncated record(s)\n"), ntrunc);
+		    gettext("%llu truncated record(s)\n"), ntrunc);
 	}
 
 	/*
@@ -1951,7 +1796,8 @@
 	if (startt == 0)
 		return;
 
+	nicenum((uint64_t)obytes / secs, nnum, sizeof (nnum));
 	(void) fprintf(stderr,
-	    gettext("%llu bytes transferred in %.6f secs (%.0f bytes/sec)\n"),
-	    obytes, secs, obytes / secs);
+	    gettext("%llu bytes transferred in %.6f secs (%sB/sec)\n"),
+	    obytes, secs, nnum);
 }