endian.h 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __endian_compat_h
  2. #define __endian_compat_h
  3. #if defined(__linux__) || defined(__CYGWIN__)
  4. #include <byteswap.h>
  5. #include_next <endian.h>
  6. #elif defined(__APPLE__)
  7. #include <netinet/in.h>
  8. #include <libkern/OSByteOrder.h>
  9. #define bswap_16(x) OSSwapInt16(x)
  10. #define bswap_32(x) OSSwapInt32(x)
  11. #define bswap_64(x) OSSwapInt64(x)
  12. #elif defined(__FreeBSD__)
  13. #include <sys/endian.h>
  14. #define bswap_16(x) bswap16(x)
  15. #define bswap_32(x) bswap32(x)
  16. #define bswap_64(x) bswap64(x)
  17. #elif defined(__OpenBSD__)
  18. #include <sys/types.h>
  19. #define bswap_16(x) __swap16(x)
  20. #define bswap_32(x) __swap32(x)
  21. #define bswap_64(x) __swap64(x)
  22. #else
  23. #include <machine/endian.h>
  24. #define bswap_16(x) swap16(x)
  25. #define bswap_32(x) swap32(x)
  26. #define bswap_64(x) swap64(x)
  27. #endif
  28. #ifndef __BYTE_ORDER
  29. #define __BYTE_ORDER BYTE_ORDER
  30. #endif
  31. #ifndef __BIG_ENDIAN
  32. #define __BIG_ENDIAN BIG_ENDIAN
  33. #endif
  34. #ifndef __LITTLE_ENDIAN
  35. #define __LITTLE_ENDIAN LITTLE_ENDIAN
  36. #endif
  37. #endif