swab.c 652 B

123456789101112131415161718
  1. #include <unistd.h>
  2. #include <sys/types.h>
  3. #include <byteswap.h>
  4. /* Updated implementation based on byteswap.h from Miles Bader
  5. * <miles@gnu.org>. This should be much faster on arches with machine
  6. * specific, optimized definitions in include/bits/byteswap.h (i.e. on
  7. * x86, use the bswap instruction on i486 and better boxes). For
  8. * platforms that lack such support, this should be no slower than it
  9. * was before... */
  10. void swab (const void *source, void *dest, ssize_t count)
  11. {
  12. const unsigned short *from = source, *from_end = from + (count >> 1);
  13. unsigned short *to = dest;
  14. while (from < from_end)
  15. *to++ = bswap_16 (*from++);
  16. }