xref: /original-bsd/lib/libc/string/swab.c (revision d272e02a)
1 /*
2  * Copyright (c) 1988 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Jeffrey Mogul.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)swab.c	5.10 (Berkeley) 03/06/91";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <string.h>
16 
17 void
18 swab(from, to, len)
19 	const void *from;
20 	void *to;
21 	size_t len;
22 {
23 	register unsigned long temp;
24 	register int n;
25 	register char *fp, *tp;
26 
27 	n = (len >> 1) + 1;
28 	fp = (char *)from;
29 	tp = (char *)to;
30 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
31 	/* round to multiple of 8 */
32 	while ((--n) & 07)
33 		STEP;
34 	n >>= 3;
35 	while (--n >= 0) {
36 		STEP; STEP; STEP; STEP;
37 		STEP; STEP; STEP; STEP;
38 	}
39 }
40