From fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Wed, 8 Jul 2015 20:46:52 -0400 Subject: Initial commit --- sys/osb/bswap2.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 sys/osb/bswap2.c (limited to 'sys/osb/bswap2.c') diff --git a/sys/osb/bswap2.c b/sys/osb/bswap2.c new file mode 100644 index 00000000..a2c08030 --- /dev/null +++ b/sys/osb/bswap2.c @@ -0,0 +1,38 @@ +/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + */ + +#define import_spp +#define import_knames +#include + +/* BSWAP2 - Move bytes from array "a" to array "b", swapping successive + * pairs of bytes. The two arrays may be the same but may not be offset + * and overlapping. + */ +BSWAP2 (a, aoff, b, boff, nbytes) +XCHAR *a; /* input array */ +XINT *aoff; /* first byte in input array */ +XCHAR *b; /* output array */ +XINT *boff; /* first byte in output array */ +XINT *nbytes; /* number of bytes to swap */ +{ + register char *ip, *op, *otop; + register unsigned temp; + + ip = (char *)a + *aoff - 1; + op = (char *)b + *boff - 1; + otop = op + (*nbytes & ~1); + + /* Swap successive pairs of bytes. + */ + while (op < otop) { + temp = *ip++; + *op++ = *ip++; + *op++ = temp; + } + + /* If there is an odd byte left, move it to the output array. + */ + if (*nbytes & 1) + *op = *ip; +} -- cgit