Subject: bin/13718: More stylish bin/dd
To: None <gnats-bugs@gnats.netbsd.org>
From: Petri Koistinen <thoron@mb-u10ip182.mbnet.fi>
List: netbsd-bugs
Date: 08/14/2001 22:44:27
>Number:         13718
>Category:       bin
>Synopsis:       More stylish bin/dd
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 14 12:40:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Petri Koistinen
>Release:        NetBSD-current 14th August 2001
>Organization:
>Environment:
System: NetBSD mb-u10ip182.mbnet.fi 1.5X NetBSD 1.5X (MUURAHAISKEKO) #8: Sat Aug 11 16:21:33 EEST 2001 thoron@mb-u10ip108.mbnet.fi:/usr/src/sys/arch/amiga/compile/MUURAHAISKEKO amiga
Architecture: m68k
Machine: amiga
>Description:
	Patches to make bin/dd comply better with style. Also little patch for
	<sys/mtio.h> file is included. File <sys/mtio.h> use typedeffed type
	"daddr_t" without defining it first. Type "daddr_t" is typedeffed in
	<sys/types.h>. This feature was found while sorting #include files in
	alphabetic order and wondering why compile fails.
>How-To-Repeat:
>Fix:
Index: mtio.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/mtio.h,v
retrieving revision 1.18
diff -u -r1.18 mtio.h
--- mtio.h	1999/09/07 13:55:27	1.18
+++ mtio.h	2001/08/14 19:20:33
@@ -38,6 +38,8 @@
 #ifndef _SYS_MTIO_H_
 #define _SYS_MTIO_H_
 
+#include <sys/types.h>
+
 /*
  * Structures and definitions for mag tape io control commands
  */

Index: args.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/args.c,v
retrieving revision 1.16
diff -u -r1.16 args.c
--- args.c	2001/07/22 13:33:58	1.16
+++ args.c	2001/08/14 19:24:49
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.16 2001/07/22 13:33:58 wiz Exp $	*/
+/* $NetBSD: args.c,v 1.16 2001/07/22 13:33:58 wiz Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -46,8 +46,8 @@
 #endif
 #endif /* not lint */
 
-#include <sys/types.h>
 #include <sys/time.h>
+#include <sys/types.h>
 
 #include <err.h>
 #include <errno.h>
@@ -59,25 +59,25 @@
 #include "dd.h"
 #include "extern.h"
 
-static int	c_arg __P((const void *, const void *));
-static int	c_conv __P((const void *, const void *));
-static void	f_bs __P((char *));
-static void	f_cbs __P((char *));
-static void	f_conv __P((char *));
-static void	f_count __P((char *));
-static void	f_files __P((char *));
-static void	f_ibs __P((char *));
-static void	f_if __P((char *));
-static void	f_obs __P((char *));
-static void	f_of __P((char *));
-static void	f_seek __P((char *));
-static void	f_skip __P((char *));
-static void	f_progress __P((char *));
-static u_long	get_bsz __P((char *));
+static int c_arg(const void *, const void *);
+static int c_conv(const void *, const void *);
+static void f_bs(char *);
+static void f_cbs(char *);
+static void f_conv(char *);
+static void f_count(char *);
+static void f_files(char *);
+static void f_ibs(char *);
+static void f_if(char *);
+static void f_obs(char *);
+static void f_of(char *);
+static void f_seek(char *);
+static void f_skip(char *);
+static void f_progress(char *);
+static u_long get_bsz(char *);
 
 static const struct arg {
 	char *name;
-	void (*f) __P((char *));
+	void (*f)(char *);
 	u_int set, noset;
 } args[] = {
      /* the array needs to be sorted by the first column so
@@ -102,8 +102,7 @@
  * args -- parse JCL syntax of dd.
  */
 void
-jcl(argv)
-	char **argv;
+jcl(char **argv)
 {
 	struct arg *ap, tmp;
 	char *arg;
@@ -190,30 +189,26 @@
 }
 
 static int
-c_arg(a, b)
-	const void *a, *b;
+c_arg(const void *a, const void *b)
 {
 	return (strcmp(((const struct arg *)a)->name,
 	    ((const struct arg *)b)->name));
 }
 
 static void
-f_bs(arg)
-	char *arg;
+f_bs(char *arg)
 {
 	in.dbsz = out.dbsz = (int)get_bsz(arg);
 }
 
 static void
-f_cbs(arg)
-	char *arg;
+f_cbs(char *arg)
 {
 	cbsz = (int)get_bsz(arg);
 }
 
 static void
-f_count(arg)
-	char *arg;
+f_count(char *arg)
 {
 	cpy_cnt = (u_int)get_bsz(arg);
 	if (!cpy_cnt)
@@ -221,59 +216,51 @@
 }
 
 static void
-f_files(arg)
-	char *arg;
+f_files(char *arg)
 {
 	files_cnt = (int)get_bsz(arg);
 }
 
 static void
-f_ibs(arg)
-	char *arg;
+f_ibs(char *arg)
 {
 	if (!(ddflags & C_BS))
 		in.dbsz = (int)get_bsz(arg);
 }
 
 static void
-f_if(arg)
-	char *arg;
+f_if(char *arg)
 {
 	in.name = arg;
 }
 
 static void
-f_obs(arg)
-	char *arg;
+f_obs(char *arg)
 {
 	if (!(ddflags & C_BS))
 		out.dbsz = (int)get_bsz(arg);
 }
 
 static void
-f_of(arg)
-	char *arg;
+f_of(char *arg)
 {
 	out.name = arg;
 }
 
 static void
-f_seek(arg)
-	char *arg;
+f_seek(char *arg)
 {
 	out.offset = (u_int)get_bsz(arg);
 }
 
 static void
-f_skip(arg)
-	char *arg;
+f_skip(char *arg)
 {
 	in.offset = (u_int)get_bsz(arg);
 }
 
 static void
-f_progress(arg)
-	char *arg;
+f_progress(char *arg)
 {
 	if (*arg != '0')
 		progress = 1;
@@ -282,8 +269,7 @@
 #ifdef	NO_CONV
 /* Build a small version (i.e. for a ramdisk root) */
 static void
-f_conv(arg)
-	char *arg;
+f_conv(char *arg)
 {
 	errx(1, "conv option disabled");
 }
@@ -312,8 +298,7 @@
 };
 
 static void
-f_conv(arg)
-	char *arg;
+f_conv(char *arg)
 {
 	struct conv *cp, tmp;
 
@@ -332,8 +317,7 @@
 }
 
 static int
-c_conv(a, b)
-	const void *a, *b;
+c_conv(const void *a, const void *b)
 {
 
 	return (strcmp(((const struct conv *)a)->name,
@@ -354,8 +338,7 @@
  *	   the product of the indicated values.
  */
 static u_long
-get_bsz(val)
-	char *val;
+get_bsz(char *val)
 {
 	u_long num, t;
 	char *expr;
@@ -370,29 +353,37 @@
 	case 'b':
 		t = num;
 		num *= 512;
-		if (t > num)
-			goto erange;
+		if (t > num) {
+			errx(1, "%s: %s", oper, strerror(ERANGE));
+			/* NOTREACHED */
+		}
 		++expr;
 		break;
 	case 'k':
 		t = num;
 		num *= 1024;
-		if (t > num)
-			goto erange;
+		if (t > num) {
+		        errx(1, "%s: %s", oper, strerror(ERANGE));
+		        /* NOTREACHED */
+		}
 		++expr;
 		break;
 	case 'm':
 		t = num;
 		num *= 1048576;
-		if (t > num)
-			goto erange;
+		if (t > num) {
+		        errx(1, "%s: %s", oper, strerror(ERANGE));
+		        /* NOTREACHED */
+		}
 		++expr;
 		break;
 	case 'w':
 		t = num;
 		num *= sizeof(int);
-		if (t > num)
-			goto erange;
+		if (t > num) {
+			errx(1, "%s: %s", oper, strerror(ERANGE));
+			/* NOTREACHED */
+		}
 		++expr;
 		break;
 	}
@@ -404,11 +395,14 @@
 	case 'x':
 		t = num;
 		num *= get_bsz(expr + 1);
-		if (t > num)
-erange:			errx(1, "%s: %s", oper, strerror(ERANGE));
+		if (t > num) {
+			errx(1, "%s: %s", oper, strerror(ERANGE));
+			/* NOTREACHED */
+		}
 		break;
 	default:
 		errx(1, "%s: illegal numeric value", oper);
+		/* NOTREACHED */
 	}
 	return (num);
 }
Index: conv.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/conv.c,v
retrieving revision 1.11
diff -u -r1.11 conv.c
--- conv.c	2001/04/28 22:47:23	1.11
+++ conv.c	2001/08/14 19:24:50
@@ -1,4 +1,4 @@
-/*	$NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $	*/
+/* $NetBSD: conv.c,v 1.11 2001/04/28 22:47:23 ross Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -62,7 +62,7 @@
  * Worst case buffer calculation is (ibs + obs - 1).
  */
 void
-def()
+def(void)
 {
 	int cnt;
 	u_char *inp;
@@ -91,23 +91,43 @@
 }
 
 void
-def_close()
+def_close(void)
 {
 	/* Just update the count, everything is already in the buffer. */
 	if (in.dbcnt)
 		out.dbcnt = in.dbcnt;
 }
 
-#ifdef	NO_CONV
+#ifdef NO_CONV
 /* Build a smaller version (i.e. for a miniroot) */
 /* These can not be called, but just in case...  */
 static char no_block[] = "unblock and -DNO_CONV?";
-void block()       { errx(1, "%s", no_block + 2); }
-void block_close() { errx(1, "%s", no_block + 2); }
-void unblock()       { errx(1, "%s", no_block); }
-void unblock_close() { errx(1, "%s", no_block); }
-#else	/* NO_CONV */
 
+void
+block(void)
+{
+	errx(1, "%s", no_block + 2);
+}
+
+void
+block_close(void)
+{
+	errx(1, "%s", no_block + 2);
+}
+
+void
+unblock(void)
+{
+	errx(1, "%s", no_block);
+}
+
+void
+unblock_close(void)
+{
+	errx(1, "%s", no_block);
+}
+#else /* NO_CONV */
+
 /*
  * Copy variable length newline terminated records with a max size cbsz
  * bytes to output.  Records less than cbs are padded with spaces.
@@ -116,7 +136,7 @@
  * max out buffer: obs + cbsz
  */
 void
-block()
+block(void)
 {
 	static int intrunc;
 	int ch = 0;	/* pacify gcc */
@@ -201,7 +221,7 @@
 }
 
 void
-block_close()
+block_close(void)
 {
 	/*
 	 * Copy any remaining data into the output buffer and pad to a record.
@@ -228,7 +248,7 @@
  * max out buffer: obs + cbsz
  */
 void
-unblock()
+unblock(void)
 {
 	int cnt;
 	u_char *inp;
@@ -262,7 +282,7 @@
 }
 
 void
-unblock_close()
+unblock_close(void)
 {
 	int cnt;
 	u_char *t;
@@ -281,4 +301,4 @@
 	}
 }
 
-#endif	/* NO_CONV */
+#endif /* NO_CONV */
Index: conv_tab.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/conv_tab.c,v
retrieving revision 1.8
diff -u -r1.8 conv_tab.c
--- conv_tab.c	1997/07/20 21:58:38	1.8
+++ conv_tab.c	2001/08/14 19:24:50
@@ -1,4 +1,4 @@
-/*	$NetBSD: conv_tab.c,v 1.8 1997/07/20 21:58:38 christos Exp $	*/
+/* $NetBSD: conv_tab.c,v 1.8 1997/07/20 21:58:38 christos Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993
Index: dd.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/dd.c,v
retrieving revision 1.20
diff -u -r1.20 dd.c
--- dd.c	2001/04/28 22:47:23	1.20
+++ dd.c	2001/08/14 19:24:52
@@ -1,4 +1,4 @@
-/*	$NetBSD: dd.c,v 1.20 2001/04/28 22:47:23 ross Exp $	*/
+/* $NetBSD: dd.c,v 1.20 2001/04/28 22:47:23 ross Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -51,10 +51,10 @@
 #endif
 #endif /* not lint */
 
-#include <sys/param.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mtio.h>
+#include <sys/param.h>
+#include <sys/stat.h>
 #include <sys/time.h>
 
 #include <ctype.h>
@@ -70,31 +70,31 @@
 #include "dd.h"
 #include "extern.h"
 
-static void dd_close __P((void));
-static void dd_in __P((void));
-static void getfdtype __P((IO *));
-static void setup __P((void));
-
-int main __P((int, char *[]));
-
-IO	in, out;		/* input/output state */
-STAT	st;			/* statistics */
-void	(*cfunc) __P((void));	/* conversion function */
-u_long	cpy_cnt;		/* # of blocks to copy */
-u_int	ddflags;		/* conversion options */
-u_int	cbsz;			/* conversion block size */
-u_int	files_cnt = 1;		/* # of files to copy */
-int	progress = 0;		/* display sign of life */
-const u_char	*ctab;		/* conversion table */
-sigset_t infoset;			/* a set blocking SIGINFO */
+static void dd_close(void);
+static void dd_in(void);
+static void getfdtype(IO *);
+static void setup(void);
+
+int main(int, char *[]);
+
+IO in, out;		/* input/output state */
+STAT st;		/* statistics */
+void (*cfunc)(void);	/* conversion function */
+u_long cpy_cnt;		/* # of blocks to copy */
+u_int ddflags;		/* conversion options */
+u_int cbsz;		/* conversion block size */
+u_int files_cnt = 1;	/* # of files to copy */
+int progress = 0;	/* display sign of life */
+const u_char *ctab;	/* conversion table */
+sigset_t infoset;	/* a set blocking SIGINFO */
 
 int
-main(argc, argv)
-	int argc;
-	char *argv[];
+main(int argc, char *argv[])
 {
 	int ch;
 
+	setprogname(argv[0]);
+
 	while ((ch = getopt(argc, argv, "")) != -1) {
 		switch (ch) {
 		default:
@@ -124,7 +124,7 @@
 }
 
 static void
-setup()
+setup(void)
 {
 	u_int cnt;
 
@@ -199,10 +199,10 @@
 	 * built-in tables.
 	 */
 	if (ddflags & (C_LCASE|C_UCASE)) {
-#ifdef	NO_CONV
+#ifdef NO_CONV
 		/* Should not get here, but just in case... */
 		errx(1, "case conv and -DNO_CONV");
-#else	/* NO_CONV */
+#else /* NO_CONV */
 		if (ddflags & C_ASCII || ddflags & C_EBCDIC) {
 			if (ddflags & C_LCASE) {
 				for (cnt = 0; cnt < 0377; ++cnt)
@@ -222,15 +222,14 @@
 		}
 
 		ctab = casetab;
-#endif	/* NO_CONV */
+#endif /* NO_CONV */
 	}
 
 	(void)gettimeofday(&st.start, NULL);	/* Statistics timestamp. */
 }
 
 static void
-getfdtype(io)
-	IO *io;
+getfdtype(IO *io)
 {
 	struct mtget mt;
 	struct stat sb;
@@ -244,7 +243,7 @@
 }
 
 static void
-dd_in()
+dd_in(void)
 {
 	int flags, n;
 
@@ -346,7 +345,7 @@
  * is truncated.
  */
 static void
-dd_close()
+dd_close(void)
 {
 	if (cfunc == def)
 		def_close();
@@ -363,8 +362,7 @@
 }
 
 void
-dd_out(force)
-	int force;
+dd_out(int force)
 {
 	static int warned;
 	int cnt, n, nw;
@@ -434,10 +432,7 @@
  * A protected against SIGINFO write
  */
 ssize_t
-bwrite(fd, buf, len)
-	int fd;
-	const void *buf;
-	size_t len;
+bwrite(int fd, const void *buf, size_t len)
 {
 	sigset_t oset;
 	ssize_t rv;
Index: dd.h
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/dd.h,v
retrieving revision 1.6
diff -u -r1.6 dd.h
--- dd.h	2001/04/28 22:47:23	1.6
+++ dd.h	2001/08/14 19:24:52
@@ -1,4 +1,4 @@
-/*	$NetBSD: dd.h,v 1.6 2001/04/28 22:47:23 ross Exp $	*/
+/* $NetBSD: dd.h,v 1.6 2001/04/28 22:47:23 ross Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -39,6 +39,9 @@
  *	@(#)dd.h	8.3 (Berkeley) 4/2/94
  */
 
+#ifndef _DD_H_
+#define _DD_H_
+
 /* Input/output stream state. */
 typedef struct {
 	u_char	*db;			/* buffer address */
@@ -96,3 +99,5 @@
 #define	C_UCASE		0x40000
 #define	C_UNBLOCK	0x80000
 #define	C_OSYNC		0x100000
+
+#endif /* !_DD_H_ */
Index: extern.h
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/extern.h,v
retrieving revision 1.10
diff -u -r1.10 extern.h
--- extern.h	2000/08/02 16:46:16	1.10
+++ extern.h	2001/08/14 19:24:52
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.10 2000/08/02 16:46:16 christos Exp $	*/
+/* $NetBSD: extern.h,v 1.10 2000/08/02 16:46:16 christos Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -39,26 +39,29 @@
  *	@(#)extern.h	8.3 (Berkeley) 4/2/94
  */
 
+#ifndef _EXTERN_H_
+#define _EXTERN_H_
+
 #include <sys/cdefs.h>
 
-void block __P((void));
-void block_close __P((void));
-void dd_out __P((int));
-void def __P((void));
-void def_close __P((void));
-void jcl __P((char **));
-void pos_in __P((void));
-void pos_out __P((void));
-void summary __P((void));
-void summaryx __P((int));
-void terminate __P((int));
-void unblock __P((void));
-void unblock_close __P((void));
-ssize_t bwrite __P((int, const void *, size_t));
+void block(void);
+void block_close(void);
+void dd_out(int);
+void def(void);
+void def_close(void);
+void jcl(char **);
+void pos_in(void);
+void pos_out(void);
+void summary(void);
+void summaryx(int);
+void terminate(int);
+void unblock(void);
+void unblock_close(void);
+ssize_t bwrite(int, const void *, size_t);
 
 extern IO in, out;
 extern STAT st;
-extern void (*cfunc) __P((void));
+extern void (*cfunc)(void);
 extern u_long cpy_cnt;
 extern u_int cbsz;
 extern u_int ddflags;
@@ -69,3 +72,5 @@
 extern const u_char e2a_32V[], e2a_POSIX[];
 extern const u_char a2ibm_32V[], a2ibm_POSIX[];
 extern u_char casetab[];
+
+#endif /* !_EXTERN_H_ */
Index: misc.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/misc.c,v
retrieving revision 1.11
diff -u -r1.11 misc.c
--- misc.c	2001/04/28 22:47:23	1.11
+++ misc.c	2001/08/14 19:24:52
@@ -1,4 +1,4 @@
-/*	$NetBSD: misc.c,v 1.11 2001/04/28 22:47:23 ross Exp $	*/
+/* $NetBSD: misc.c,v 1.11 2001/04/28 22:47:23 ross Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -46,15 +46,15 @@
 #endif
 #endif /* not lint */
 
-#include <sys/types.h>
 #include <sys/time.h>
+#include <sys/types.h>
 
 #include <err.h>
+#include <inttypes.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <inttypes.h>
 
 #include "dd.h"
 #include "extern.h"
@@ -62,7 +62,7 @@
 #define	tv2mS(tv) ((tv).tv_sec * 1000LL + ((tv).tv_usec + 500) / 1000)
 
 void
-summary()
+summary(void)
 {
 	char buf[100];
 	int64_t mS;
@@ -101,19 +101,15 @@
 
 /* ARGSUSED */
 void
-summaryx(notused)
-	int notused;
+summaryx(int notused)
 {
-
 	summary();
 }
 
 /* ARGSUSED */
 void
-terminate(notused)
-	int notused;
+terminate(int notused)
 {
-
 	exit(0);
 	/* NOTREACHED */
 }
Index: position.c
===================================================================
RCS file: /cvsroot/basesrc/bin/dd/position.c,v
retrieving revision 1.10
diff -u -r1.10 position.c
--- position.c	2001/04/28 22:47:23	1.10
+++ position.c	2001/08/14 19:24:52
@@ -1,4 +1,4 @@
-/*	$NetBSD: position.c,v 1.10 2001/04/28 22:47:23 ross Exp $	*/
+/* $NetBSD: position.c,v 1.10 2001/04/28 22:47:23 ross Exp $ */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -46,11 +46,11 @@
 #endif
 #endif /* not lint */
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mtio.h>
+#include <sys/stat.h>
 #include <sys/time.h>
+#include <sys/types.h>
 
 #include <err.h>
 #include <errno.h>
@@ -67,7 +67,7 @@
  * output.
  */
 void
-pos_in()
+pos_in(void)
 {
 	int bcnt, cnt, nr, warned;
 
@@ -122,7 +122,7 @@
 }
 
 void
-pos_out()
+pos_out(void)
 {
 	struct mtop t_op;
 	int cnt, n;
>Release-Note:
>Audit-Trail:
>Unformatted: