1*34822Sbostic /* 2*34822Sbostic * Copyright (c) 1988 Regents of the University of California. 3*34822Sbostic * All rights reserved. 4*34822Sbostic * 5*34822Sbostic * Redistribution and use in source and binary forms are permitted 6*34822Sbostic * provided that the above copyright notice and this paragraph are 7*34822Sbostic * duplicated in all such forms and that any documentation, 8*34822Sbostic * advertising materials, and other materials related to such 9*34822Sbostic * distribution and use acknowledge that the software was developed 10*34822Sbostic * by the University of California, Berkeley. The name of the 11*34822Sbostic * University may not be used to endorse or promote products derived 12*34822Sbostic * from this software without specific prior written permission. 13*34822Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*34822Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*34822Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16*34822Sbostic */ 17*34822Sbostic 1826601Sdonn #if defined(LIBC_SCCS) && !defined(lint) 19*34822Sbostic static char sccsid[] = "@(#)swab.c 5.4 (Berkeley) 06/27/88"; 20*34822Sbostic #endif /* LIBC_SCCS and not lint */ 2113426Ssam 221991Swnj /* 2313426Ssam * Swab bytes 2413426Ssam * Jeffrey Mogul, Stanford 251991Swnj */ 261991Swnj 2713426Ssam swab(from, to, n) 2813426Ssam register char *from, *to; 2913426Ssam register int n; 301991Swnj { 3113426Ssam register unsigned long temp; 32*34822Sbostic 3313426Ssam n >>= 1; n++; 3413426Ssam #define STEP temp = *from++,*to++ = *from++,*to++ = temp 3513426Ssam /* round to multiple of 8 */ 3613426Ssam while ((--n) & 07) 3713426Ssam STEP; 3813426Ssam n >>= 3; 391991Swnj while (--n >= 0) { 4013426Ssam STEP; STEP; STEP; STEP; 4113426Ssam STEP; STEP; STEP; STEP; 421991Swnj } 431991Swnj } 44