endian-win.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef ENDIAN_WIN_H_
  2. #define ENDIAN_WIN_H_
  3. #include "byteswap-win.h"
  4. #define LITTLE_ENDIAN 1
  5. #define BIG_ENDIAN 2
  6. #define BYTE_ORDER LITTLE_ENDIAN
  7. static inline uint16_t htobe16(uint16_t v)
  8. {
  9. if (BYTE_ORDER == LITTLE_ENDIAN)
  10. return bswap_16(v);
  11. return v;
  12. }
  13. static inline uint16_t htole16(uint16_t v)
  14. {
  15. if (BYTE_ORDER == BIG_ENDIAN)
  16. return bswap_16(v);
  17. return v;
  18. }
  19. static inline uint16_t be16toh(uint16_t v)
  20. {
  21. if (BYTE_ORDER == LITTLE_ENDIAN)
  22. return bswap_16(v);
  23. return v;
  24. }
  25. static inline uint16_t le16toh(uint16_t v)
  26. {
  27. if (BYTE_ORDER == BIG_ENDIAN)
  28. return bswap_16(v);
  29. return v;
  30. }
  31. static inline uint32_t htobe32(uint32_t v)
  32. {
  33. if (BYTE_ORDER == LITTLE_ENDIAN)
  34. return bswap_32(v);
  35. return v;
  36. }
  37. static inline uint32_t htole32(uint32_t v)
  38. {
  39. if (BYTE_ORDER == BIG_ENDIAN)
  40. return bswap_32(v);
  41. return v;
  42. }
  43. static inline uint32_t be32toh(uint32_t v)
  44. {
  45. if (BYTE_ORDER == LITTLE_ENDIAN)
  46. return bswap_32(v);
  47. return v;
  48. }
  49. static inline uint32_t le32toh(uint32_t v)
  50. {
  51. if (BYTE_ORDER == BIG_ENDIAN)
  52. return bswap_32(v);
  53. return v;
  54. }
  55. #endif /* ENDIAN_WIN_H_ */