Add include files to get prototype declarations, and fix bugs found.
[unix-history] / usr / src / lib / libc / string / swab.c
index f649306..69417db 100644 (file)
@@ -1,17 +1,38 @@
-/* @(#)swab.c  4.1 (Berkeley) %G% */
 /*
 /*
- * Swap bytes in 16-bit [half-]words
- * for going between the 11 and the interdata
+ * Copyright (c) 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Jeffrey Mogul.
+ *
+ * %sccs.include.redist.c%
  */
 
  */
 
-swab(pf, pt, n)
-register short *pf, *pt;
-register n;
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)swab.c     5.9 (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <string.h>
+
+void
+swab(from, to, n)
+       const void *from;
+       void *to;
+       register size_t n;
 {
 {
+       register char *fp, *tp;
+       register unsigned long temp;
 
 
-       n /= 2;
+       n >>= 1; n++;
+       fp = (char *)from;
+       tp = (char *)to;
+#define        STEP    temp = *fp++,*tp++ = *fp++,*tp++ = temp
+       /* round to multiple of 8 */
+       while ((--n) & 07)
+               STEP;
+       n >>= 3;
        while (--n >= 0) {
        while (--n >= 0) {
-               *pt++ = (*pf << 8) + ((*pf >> 8) & 0377);
-               pf++;
+               STEP; STEP; STEP; STEP;
+               STEP; STEP; STEP; STEP;
        }
 }
        }
 }