134822Sbostic /* 234822Sbostic * Copyright (c) 1988 Regents of the University of California. 334822Sbostic * All rights reserved. 434822Sbostic * 5*42181Sbostic * This code is derived from software contributed to Berkeley by 6*42181Sbostic * Jeffrey Mogul. 7*42181Sbostic * 834822Sbostic * Redistribution and use in source and binary forms are permitted 934822Sbostic * provided that the above copyright notice and this paragraph are 1034822Sbostic * duplicated in all such forms and that any documentation, 1134822Sbostic * advertising materials, and other materials related to such 1234822Sbostic * distribution and use acknowledge that the software was developed 1334822Sbostic * by the University of California, Berkeley. The name of the 1434822Sbostic * University may not be used to endorse or promote products derived 1534822Sbostic * from this software without specific prior written permission. 1634822Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 1734822Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 1834822Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1934822Sbostic */ 2034822Sbostic 2126601Sdonn #if defined(LIBC_SCCS) && !defined(lint) 22*42181Sbostic static char sccsid[] = "@(#)swab.c 5.5 (Berkeley) 05/17/90"; 2334822Sbostic #endif /* LIBC_SCCS and not lint */ 2413426Ssam 25*42181Sbostic #include <string.h> 261991Swnj 27*42181Sbostic void 2813426Ssam swab(from, to, n) 2913426Ssam register char *from, *to; 3013426Ssam register int n; 311991Swnj { 3213426Ssam register unsigned long temp; 3334822Sbostic 3413426Ssam n >>= 1; n++; 3513426Ssam #define STEP temp = *from++,*to++ = *from++,*to++ = temp 3613426Ssam /* round to multiple of 8 */ 3713426Ssam while ((--n) & 07) 3813426Ssam STEP; 3913426Ssam n >>= 3; 401991Swnj while (--n >= 0) { 4113426Ssam STEP; STEP; STEP; STEP; 4213426Ssam STEP; STEP; STEP; STEP; 431991Swnj } 441991Swnj } 45