xref: /csrg-svn/lib/libc/string/swab.c (revision 46613)
134822Sbostic /*
234822Sbostic  * Copyright (c) 1988 Regents of the University of California.
334822Sbostic  * All rights reserved.
434822Sbostic  *
542181Sbostic  * This code is derived from software contributed to Berkeley by
642181Sbostic  * Jeffrey Mogul.
742181Sbostic  *
842637Sbostic  * %sccs.include.redist.c%
934822Sbostic  */
1034822Sbostic 
1126601Sdonn #if defined(LIBC_SCCS) && !defined(lint)
12*46613Sbostic static char sccsid[] = "@(#)swab.c	5.9 (Berkeley) 02/24/91";
1334822Sbostic #endif /* LIBC_SCCS and not lint */
1413426Ssam 
1542181Sbostic #include <string.h>
161991Swnj 
1742181Sbostic void
1813426Ssam swab(from, to, n)
19*46613Sbostic 	const void *from;
20*46613Sbostic 	void *to;
21*46613Sbostic 	register size_t n;
221991Swnj {
23*46613Sbostic 	register char *fp, *tp;
2413426Ssam 	register unsigned long temp;
2534822Sbostic 
2613426Ssam 	n >>= 1; n++;
27*46613Sbostic 	fp = (char *)from;
28*46613Sbostic 	tp = (char *)to;
29*46613Sbostic #define	STEP	temp = *fp++,*tp++ = *fp++,*tp++ = temp
3013426Ssam 	/* round to multiple of 8 */
3113426Ssam 	while ((--n) & 07)
3213426Ssam 		STEP;
3313426Ssam 	n >>= 3;
341991Swnj 	while (--n >= 0) {
3513426Ssam 		STEP; STEP; STEP; STEP;
3613426Ssam 		STEP; STEP; STEP; STEP;
371991Swnj 	}
381991Swnj }
39