Module Name:    src
Committed By:   christos
Date:           Sat Apr 17 17:57:39 UTC 2010

Modified Files:
        src/lib/libc/string: swab.3 swab.c

Log Message:
Change and document for POSIX compliance.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/string/swab.3
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/string/swab.c

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

Modified files:

Index: src/lib/libc/string/swab.3
diff -u src/lib/libc/string/swab.3:1.10 src/lib/libc/string/swab.3:1.11
--- src/lib/libc/string/swab.3:1.10	Sat Apr 17 13:50:13 2010
+++ src/lib/libc/string/swab.3	Sat Apr 17 13:57:39 2010
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     from: @(#)swab.3	8.1 (Berkeley) 6/4/93
-.\"	$NetBSD: swab.3,v 1.10 2010/04/17 17:50:13 christos Exp $
+.\"	$NetBSD: swab.3,v 1.11 2010/04/17 17:57:39 christos Exp $
 .\"
 .Dd April 17, 2010
 .Dt SWAB 3
@@ -51,9 +51,17 @@
 .Fa dst ,
 swapping adjacent bytes.
 .Pp
-The argument
+If 
 .Fa len
-must be even number.
+is negative or zero
+.Nm
+does nothing.
+If
+.Fa len
+is odd,
+.Nm copies
+.Fa len - 1
+bytes and the disposition of the last byte is unspecified.
 .Sh SEE ALSO
 .Xr bzero 3 ,
 .Xr memset 3

Index: src/lib/libc/string/swab.c
diff -u src/lib/libc/string/swab.c:1.12 src/lib/libc/string/swab.c:1.13
--- src/lib/libc/string/swab.c:1.12	Thu Aug  7 12:43:53 2003
+++ src/lib/libc/string/swab.c	Sat Apr 17 13:57:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: swab.c,v 1.12 2003/08/07 16:43:53 agc Exp $	*/
+/*	$NetBSD: swab.c,v 1.13 2010/04/17 17:57:39 christos Exp $	*/
 
 /*
  * Copyright (c) 1988, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)swab.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: swab.c,v 1.12 2003/08/07 16:43:53 agc Exp $");
+__RCSID("$NetBSD: swab.c,v 1.13 2010/04/17 17:57:39 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -45,12 +45,17 @@
 #include <unistd.h>
 
 void
-swab(const void *from, void *to, size_t len)
+swab(const void * __restrict from, void * __restrict to, ssize_t len)
 {
 	char temp;
 	const char *fp;
 	char *tp;
 
+	if (len & 1)
+		len--;
+	if (len <= 0)
+		return;
+
 	_DIAGASSERT(from != NULL);
 	_DIAGASSERT(to != NULL);
 

Reply via email to