xref: /csrg-svn/lib/libc/string/swab.c (revision 42181)
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  * Redistribution and use in source and binary forms are permitted
9  * provided that the above copyright notice and this paragraph are
10  * duplicated in all such forms and that any documentation,
11  * advertising materials, and other materials related to such
12  * distribution and use acknowledge that the software was developed
13  * by the University of California, Berkeley.  The name of the
14  * University may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19  */
20 
21 #if defined(LIBC_SCCS) && !defined(lint)
22 static char sccsid[] = "@(#)swab.c	5.5 (Berkeley) 05/17/90";
23 #endif /* LIBC_SCCS and not lint */
24 
25 #include <string.h>
26 
27 void
28 swab(from, to, n)
29 	register char *from, *to;
30 	register int n;
31 {
32 	register unsigned long temp;
33 
34 	n >>= 1; n++;
35 #define	STEP	temp = *from++,*to++ = *from++,*to++ = temp
36 	/* round to multiple of 8 */
37 	while ((--n) & 07)
38 		STEP;
39 	n >>= 3;
40 	while (--n >= 0) {
41 		STEP; STEP; STEP; STEP;
42 		STEP; STEP; STEP; STEP;
43 	}
44 }
45