aboutsummaryrefslogtreecommitdiff
path: root/sys/osb/bswap4.c
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/osb/bswap4.c
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/osb/bswap4.c')
-rw-r--r--sys/osb/bswap4.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/sys/osb/bswap4.c b/sys/osb/bswap4.c
new file mode 100644
index 00000000..763633a5
--- /dev/null
+++ b/sys/osb/bswap4.c
@@ -0,0 +1,46 @@
+/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+ */
+
+#define import_spp
+#define import_knames
+#include <iraf.h>
+
+/* BSWAP4 - Move bytes from array "a" to array "b", swapping the four bytes
+ * in each successive 4 byte group, i.e., 12345678 becomes 43218765.
+ * The input and output arrays may be the same but may not partially overlap.
+ */
+BSWAP4 (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, *tp;
+ register int n;
+ static char temp[4];
+
+ tp = temp;
+ ip = (char *)a + *aoff - 1;
+ op = (char *)b + *boff - 1;
+
+ /* Swap successive four byte groups.
+ */
+ for (n = *nbytes >> 2; --n >= 0; ) {
+ *tp++ = *ip++;
+ *tp++ = *ip++;
+ *tp++ = *ip++;
+ *tp++ = *ip++;
+ *op++ = *--tp;
+ *op++ = *--tp;
+ *op++ = *--tp;
+ *op++ = *--tp;
+ }
+
+ /* If there are any odd bytes left, move them to the output array.
+ * Do not bother to swap as it is unclear how to swap a partial
+ * group, and really incorrect if the data is not modulus 4.
+ */
+ for (n = *nbytes & 03; --n >= 0; )
+ *op++ = *ip++;
+}