Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/string Change and document for POSIX compliance.



details:   https://anonhg.NetBSD.org/src/rev/9cdf13e167b2
branches:  trunk
changeset: 754044:9cdf13e167b2
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 17 17:57:39 2010 +0000

description:
Change and document for POSIX compliance.

diffstat:

 lib/libc/string/swab.3 |  14 +++++++++++---
 lib/libc/string/swab.c |  11 ++++++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diffs (69 lines):

diff -r 06f3e57205b8 -r 9cdf13e167b2 lib/libc/string/swab.3
--- a/lib/libc/string/swab.3    Sat Apr 17 17:51:47 2010 +0000
+++ b/lib/libc/string/swab.3    Sat Apr 17 17:57:39 2010 +0000
@@ -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
diff -r 06f3e57205b8 -r 9cdf13e167b2 lib/libc/string/swab.c
--- a/lib/libc/string/swab.c    Sat Apr 17 17:51:47 2010 +0000
+++ b/lib/libc/string/swab.c    Sat Apr 17 17:57:39 2010 +0000
@@ -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);
 



Home | Main Index | Thread Index | Old Index