xref: /original-bsd/lib/libc/string/swab.c (revision 21439bbc)
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.9 (Berkeley) 02/24/91";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <string.h>
16 
17 void
18 swab(from, to, n)
19 	const void *from;
20 	void *to;
21 	register size_t n;
22 {
23 	register char *fp, *tp;
24 	register unsigned long temp;
25 
26 	n >>= 1; n++;
27 	fp = (char *)from;
28 	tp = (char *)to;
29 #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
30 	/* round to multiple of 8 */
31 	while ((--n) & 07)
32 		STEP;
33 	n >>= 3;
34 	while (--n >= 0) {
35 		STEP; STEP; STEP; STEP;
36 		STEP; STEP; STEP; STEP;
37 	}
38 }
39