swab.c 799 B

1234567891011121314151617181920212223
  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 junk;
  14. unsigned short *to = dest;
  15. while (from < from_end) {
  16. /* Don't put '*from++'into the bswap_16() macros
  17. * or mad things will happen on macro expansion */
  18. junk=*from++;
  19. *to++ = bswap_16 (junk);
  20. }
  21. }