summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/string/swab.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c
index b53717dcde..b74db7e62a 100644
--- a/src/lib/libc/string/swab.c
+++ b/src/lib/libc/string/swab.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: swab.c,v 1.7 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: swab.c,v 1.8 2008/03/15 21:54:09 ray Exp $ */
2/* 2/*
3 * Copyright (c) 1988 Regents of the University of California. 3 * Copyright (c) 1988 Regents of the University of California.
4 * All rights reserved. 4 * All rights reserved.
@@ -36,19 +36,25 @@
36void 36void
37swab(const void *from, void *to, size_t len) 37swab(const void *from, void *to, size_t len)
38{ 38{
39 unsigned long temp; 39 size_t n;
40 int n;
41 char *fp, *tp; 40 char *fp, *tp;
41 char temp;
42 42
43 n = (len >> 1) + 1; 43 n = (len / 2) + 1;
44 fp = (char *)from; 44 fp = (char *)from;
45 tp = (char *)to; 45 tp = (char *)to;
46#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp 46#define STEP do { \
47 temp = *fp++; \
48 *tp++ = *fp++; \
49 *tp++ = temp; \
50} while (0)
47 /* round to multiple of 8 */ 51 /* round to multiple of 8 */
48 while ((--n) & 07) 52 while ((--n) & 07)
49 STEP; 53 STEP;
50 n >>= 3; 54 n >>= 3;
51 while (--n >= 0) { 55 if (n == 0)
56 return;
57 while (n-- != 0) {
52 STEP; STEP; STEP; STEP; 58 STEP; STEP; STEP; STEP;
53 STEP; STEP; STEP; STEP; 59 STEP; STEP; STEP; STEP;
54 } 60 }