Commit | Line | Data |
---|---|---|
5862c605 KB |
1 | /* |
2 | * Copyright (c) 1988 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
336401ac KB |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Jeffrey Mogul. | |
7 | * | |
019bea33 | 8 | * %sccs.include.redist.c% |
5862c605 KB |
9 | */ |
10 | ||
2ce81398 | 11 | #if defined(LIBC_SCCS) && !defined(lint) |
3422a8a3 | 12 | static char sccsid[] = "@(#)swab.c 5.10 (Berkeley) %G%"; |
5862c605 | 13 | #endif /* LIBC_SCCS and not lint */ |
fce15cd6 | 14 | |
336401ac | 15 | #include <string.h> |
d0603900 | 16 | |
336401ac | 17 | void |
be7122f8 | 18 | swab(from, to, len) |
46b5f26a KB |
19 | const void *from; |
20 | void *to; | |
be7122f8 | 21 | size_t len; |
d0603900 | 22 | { |
fce15cd6 | 23 | register unsigned long temp; |
be7122f8 KB |
24 | register int n; |
25 | register char *fp, *tp; | |
5862c605 | 26 | |
be7122f8 | 27 | n = (len >> 1) + 1; |
46b5f26a KB |
28 | fp = (char *)from; |
29 | tp = (char *)to; | |
30 | #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp | |
fce15cd6 SL |
31 | /* round to multiple of 8 */ |
32 | while ((--n) & 07) | |
33 | STEP; | |
34 | n >>= 3; | |
d0603900 | 35 | while (--n >= 0) { |
fce15cd6 SL |
36 | STEP; STEP; STEP; STEP; |
37 | STEP; STEP; STEP; STEP; | |
d0603900 BJ |
38 | } |
39 | } |