134822Sbostic /* 2*61193Sbostic * Copyright (c) 1988, 1993 3*61193Sbostic * The Regents of the University of California. 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*61193Sbostic static char sccsid[] = "@(#)swab.c 8.1 (Berkeley) 06/04/93"; 1334822Sbostic #endif /* LIBC_SCCS and not lint */ 1413426Ssam 1542181Sbostic #include <string.h> 161991Swnj 1742181Sbostic void swab(from,to,len)1847035Sbosticswab(from, to, len) 1946613Sbostic const void *from; 2046613Sbostic void *to; 2147035Sbostic size_t len; 221991Swnj { 2347035Sbostic register unsigned long temp; 2447035Sbostic register int n; 2546613Sbostic register char *fp, *tp; 2634822Sbostic 2747035Sbostic n = (len >> 1) + 1; 2846613Sbostic fp = (char *)from; 2946613Sbostic tp = (char *)to; 3046613Sbostic #define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp 3113426Ssam /* round to multiple of 8 */ 3213426Ssam while ((--n) & 07) 3313426Ssam STEP; 3413426Ssam n >>= 3; 351991Swnj while (--n >= 0) { 3613426Ssam STEP; STEP; STEP; STEP; 3713426Ssam STEP; STEP; STEP; STEP; 381991Swnj } 391991Swnj } 40