Module Name:    src
Committed By:   mrg
Date:           Fri Oct  4 08:57:38 UTC 2019

Modified Files:
        src/bin/dd: Makefile dd.c extern.h
Added Files:
        src/bin/dd: dd_swab.c

Log Message:
copy libc's swab.c into dd as dd_swab(), and remove the restrict.

our implementation was fine, but the restrict marker is problematic
as gcc 8 is now more strict about checking for restrict issues.

this is the only actual consumer of swab(3) in our tree, though,
besides the test for it.  oh well.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/bin/dd/Makefile
cvs rdiff -u -r1.52 -r1.53 src/bin/dd/dd.c
cvs rdiff -u -r0 -r1.1 src/bin/dd/dd_swab.c
cvs rdiff -u -r1.23 -r1.24 src/bin/dd/extern.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/dd/Makefile
diff -u src/bin/dd/Makefile:1.19 src/bin/dd/Makefile:1.20
--- src/bin/dd/Makefile:1.19	Sun Sep 15 23:58:31 2019
+++ src/bin/dd/Makefile	Fri Oct  4 08:57:37 2019
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.19 2019/09/15 23:58:31 kamil Exp $
+#	$NetBSD: Makefile,v 1.20 2019/10/04 08:57:37 mrg Exp $
 #	@(#)Makefile	8.1 (Berkeley) 5/31/93
 
 .include <bsd.own.mk>
 
 RUMPPRG=dd
-SRCS=	args.c conv.c dd.c misc.c position.c
+SRCS=	args.c conv.c dd.c dd_swab.c misc.c position.c
 
 DPADD+=	${LIBUTIL}
 LDADD+=	-lutil

Index: src/bin/dd/dd.c
diff -u src/bin/dd/dd.c:1.52 src/bin/dd/dd.c:1.53
--- src/bin/dd/dd.c:1.52	Sat Mar 23 09:33:16 2019
+++ src/bin/dd/dd.c	Fri Oct  4 08:57:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: dd.c,v 1.52 2019/03/23 09:33:16 mlelstv Exp $	*/
+/*	$NetBSD: dd.c,v 1.53 2019/10/04 08:57:37 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dd.c	8.5 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: dd.c,v 1.52 2019/03/23 09:33:16 mlelstv Exp $");
+__RCSID("$NetBSD: dd.c,v 1.53 2019/10/04 08:57:37 mrg Exp $");
 #endif
 #endif /* not lint */
 
@@ -456,7 +456,7 @@ dd_in(void)
 				++st.swab;
 				--n;
 			}
-			swab(in.dbp, in.dbp, n);
+			dd_swab(in.dbp, in.dbp, n);
 		}
 
 		in.dbp += in.dbrcnt;

Index: src/bin/dd/extern.h
diff -u src/bin/dd/extern.h:1.23 src/bin/dd/extern.h:1.24
--- src/bin/dd/extern.h:1.23	Wed Mar 18 13:23:49 2015
+++ src/bin/dd/extern.h	Fri Oct  4 08:57:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: extern.h,v 1.23 2015/03/18 13:23:49 manu Exp $	*/
+/*	$NetBSD: extern.h,v 1.24 2019/10/04 08:57:38 mrg Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -84,3 +84,5 @@ extern const u_char	e2a_32V[], e2a_POSIX
 extern const u_char	a2ibm_32V[], a2ibm_POSIX[];
 extern u_char		casetab[];
 extern const char	*msgfmt;
+
+void dd_swab(const void *, void *, ssize_t len);

Added files:

Index: src/bin/dd/dd_swab.c
diff -u /dev/null src/bin/dd/dd_swab.c:1.1
--- /dev/null	Fri Oct  4 08:57:38 2019
+++ src/bin/dd/dd_swab.c	Fri Oct  4 08:57:38 2019
@@ -0,0 +1,83 @@
+/*	$NetBSD: dd_swab.c,v 1.1 2019/10/04 08:57:38 mrg Exp $	*/
+
+/*
+ * Copyright (c) 1988, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Jeffrey Mogul.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp
+ */
+
+/* This copy has no restrict on it, that dd wants */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)swab.c	8.1 (Berkeley) 6/4/93";
+#else
+__RCSID("$NetBSD: dd_swab.c,v 1.1 2019/10/04 08:57:38 mrg Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+
+#include "dd.h"
+#include "extern.h"
+
+void
+dd_swab(const void * from, void * to, ssize_t len)
+{
+	char temp;
+	const char *fp;
+	char *tp;
+
+	if (len <= 1)
+		return;
+
+	len /= 2;
+	fp = (const char *)from;
+	tp = (char *)to;
+#define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
+
+	if (__predict_false(len == 1)) {
+		STEP;
+		return;
+	}
+
+	/* round to multiple of 8 */
+	while ((--len % 8) != 0)
+		STEP;
+	len /= 8;
+	if (len == 0)
+		return;
+	while (len-- != 0) {
+		STEP; STEP; STEP; STEP;
+		STEP; STEP; STEP; STEP;
+	}
+}

Reply via email to