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