1 /* @(#)swabbytes.c 1.10 10/08/21 Copyright 1988, 1995-2010 J. Schilling */ 2 /* 3 * swab bytes in memory 4 * 5 * Copyright (c) 1988, 1995-2010 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #include <schily/standard.h> 22 #include <schily/types.h> 23 #include <schily/schily.h> 24 25 #define DO8(a) a; a; a; a; a; a; a; a; 26 27 EXPORT void swabbytes(vp,cnt)28swabbytes(vp, cnt) 29 void *vp; 30 register ssize_t cnt; 31 { 32 register char *bp = (char *)vp; 33 register char c; 34 35 cnt /= 2; /* even count only */ 36 while ((cnt -= 8) >= 0) { 37 /* CSTYLED */ 38 DO8(c = *bp++; bp[-1] = *bp; *bp++ = c;); 39 } 40 cnt += 8; 41 while (--cnt >= 0) { 42 c = *bp++; bp[-1] = *bp; *bp++ = c; 43 } 44 } 45