diff options
Diffstat (limited to 'src/lib/libc/string/swab.c')
-rw-r--r-- | src/lib/libc/string/swab.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/lib/libc/string/swab.c b/src/lib/libc/string/swab.c index f33fc53bd6..b74db7e62a 100644 --- a/src/lib/libc/string/swab.c +++ b/src/lib/libc/string/swab.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* $OpenBSD: swab.c,v 1.8 2008/03/15 21:54:09 ray Exp $ */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | 3 | * Copyright (c) 1988 Regents of the University of California. |
3 | * All rights reserved. | 4 | * All rights reserved. |
@@ -13,11 +14,7 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 15 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 16 | * documentation and/or other materials provided with the distribution. |
16 | * 3. All advertising materials mentioning features or use of this software | 17 | * 3. Neither the name of the University nor the names of its contributors |
17 | * must display the following acknowledgement: | ||
18 | * This product includes software developed by the University of | ||
19 | * California, Berkeley and its contributors. | ||
20 | * 4. Neither the name of the University nor the names of its contributors | ||
21 | * may be used to endorse or promote products derived from this software | 18 | * may be used to endorse or promote products derived from this software |
22 | * without specific prior written permission. | 19 | * without specific prior written permission. |
23 | * | 20 | * |
@@ -34,32 +31,30 @@ | |||
34 | * SUCH DAMAGE. | 31 | * SUCH DAMAGE. |
35 | */ | 32 | */ |
36 | 33 | ||
37 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #include <unistd.h> |
38 | /*static char *sccsid = "from: @(#)swab.c 5.10 (Berkeley) 3/6/91";*/ | ||
39 | static char *rcsid = "$Id: swab.c,v 1.1.1.1 1995/10/18 08:42:23 deraadt Exp $"; | ||
40 | #endif /* LIBC_SCCS and not lint */ | ||
41 | |||
42 | #include <string.h> | ||
43 | 35 | ||
44 | void | 36 | void |
45 | swab(from, to, len) | 37 | swab(const void *from, void *to, size_t len) |
46 | const void *from; | ||
47 | void *to; | ||
48 | size_t len; | ||
49 | { | 38 | { |
50 | register unsigned long temp; | 39 | size_t n; |
51 | register int n; | 40 | char *fp, *tp; |
52 | register char *fp, *tp; | 41 | char temp; |
53 | 42 | ||
54 | n = (len >> 1) + 1; | 43 | n = (len / 2) + 1; |
55 | fp = (char *)from; | 44 | fp = (char *)from; |
56 | tp = (char *)to; | 45 | tp = (char *)to; |
57 | #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | 46 | #define STEP do { \ |
47 | temp = *fp++; \ | ||
48 | *tp++ = *fp++; \ | ||
49 | *tp++ = temp; \ | ||
50 | } while (0) | ||
58 | /* round to multiple of 8 */ | 51 | /* round to multiple of 8 */ |
59 | while ((--n) & 07) | 52 | while ((--n) & 07) |
60 | STEP; | 53 | STEP; |
61 | n >>= 3; | 54 | n >>= 3; |
62 | while (--n >= 0) { | 55 | if (n == 0) |
56 | return; | ||
57 | while (n-- != 0) { | ||
63 | STEP; STEP; STEP; STEP; | 58 | STEP; STEP; STEP; STEP; |
64 | STEP; STEP; STEP; STEP; | 59 | STEP; STEP; STEP; STEP; |
65 | } | 60 | } |