2
0

_endian.h 1.0 KB

123456789101112131415161718192021222324252627282930
  1. #if !defined(_MSC_VER)
  2. # include <unistd.h>
  3. #endif
  4. #include <stdlib.h>
  5. #include <stdint.h>
  6. #if defined (__SVR4) && defined (__sun)
  7. #include <sys/isa_defs.h>
  8. #endif
  9. #if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \
  10. (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || \
  11. (defined(_BIG_ENDIAN) && defined(__SVR4) && defined(__sun))
  12. #define BORG_BIG_ENDIAN 1
  13. #elif (defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || \
  14. (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
  15. (defined(_LITTLE_ENDIAN) && defined(__SVR4) && defined(__sun)) || \
  16. (defined(_MSC_VER) && (defined(_M_AMD64) || defined(_M_IX86)))
  17. #define BORG_BIG_ENDIAN 0
  18. #else
  19. #error Unknown byte order
  20. #endif
  21. #if BORG_BIG_ENDIAN
  22. #define _le32toh(x) __builtin_bswap32(x)
  23. #define _htole32(x) __builtin_bswap32(x)
  24. #else
  25. #define _le32toh(x) (x)
  26. #define _htole32(x) (x)
  27. #endif