xref: /csrg-svn/lib/libc/string/swab.c (revision 26601)
1*26601Sdonn #if defined(LIBC_SCCS) && !defined(lint)
2*26601Sdonn static char sccsid[] = "@(#)swab.c	5.3 (Berkeley) 03/09/86";
3*26601Sdonn #endif LIBC_SCCS and not lint
413426Ssam 
51991Swnj /*
613426Ssam  * Swab bytes
713426Ssam  * Jeffrey Mogul, Stanford
81991Swnj  */
91991Swnj 
1013426Ssam swab(from, to, n)
1113426Ssam 	register char *from, *to;
1213426Ssam 	register int n;
131991Swnj {
1413426Ssam 	register unsigned long temp;
1513426Ssam 
1613426Ssam 	n >>= 1; n++;
1713426Ssam #define	STEP	temp = *from++,*to++ = *from++,*to++ = temp
1813426Ssam 	/* round to multiple of 8 */
1913426Ssam 	while ((--n) & 07)
2013426Ssam 		STEP;
2113426Ssam 	n >>= 3;
221991Swnj 	while (--n >= 0) {
2313426Ssam 		STEP; STEP; STEP; STEP;
2413426Ssam 		STEP; STEP; STEP; STEP;
251991Swnj 	}
261991Swnj }
27