yrmcds_portability.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /** @file yrmcds_portability.h
  2. *
  3. * Private header file for OS portability.
  4. *
  5. * Some code are copied from a public domain source at:
  6. * https://gist.github.com/yinyin/2027912
  7. *
  8. * This is public domain, too.
  9. */
  10. #pragma once
  11. #ifndef YRMCDS_PORTABILITY_H_INCLUDED
  12. #define YRMCDS_PORTABILITY_H_INCLUDED
  13. #if defined(__APPLE__)
  14. # include <libkern/OSByteOrder.h>
  15. # define htobe16(x) OSSwapHostToBigInt16(x)
  16. # define htole16(x) OSSwapHostToLittleInt16(x)
  17. # define be16toh(x) OSSwapBigToHostInt16(x)
  18. # define le16toh(x) OSSwapLittleToHostInt16(x)
  19. # define htobe32(x) OSSwapHostToBigInt32(x)
  20. # define htole32(x) OSSwapHostToLittleInt32(x)
  21. # define be32toh(x) OSSwapBigToHostInt32(x)
  22. # define le32toh(x) OSSwapLittleToHostInt32(x)
  23. # define htobe64(x) OSSwapHostToBigInt64(x)
  24. # define htole64(x) OSSwapHostToLittleInt64(x)
  25. # define be64toh(x) OSSwapBigToHostInt64(x)
  26. # define le64toh(x) OSSwapLittleToHostInt64(x)
  27. #elif defined(__linux__)
  28. # include <endian.h>
  29. #elif defined(sun) // Solaris
  30. # include <sys/byteorder.h>
  31. # define htobe16(x) BE_16(x)
  32. # define htole16(x) LE_16(x)
  33. # define be16toh(x) BE_IN16(x)
  34. # define le16toh(x) LE_IN16(x)
  35. # define htobe32(x) BE_32(x)
  36. # define htole32(x) LE_32(x)
  37. # define be32toh(x) BE_IN32(x)
  38. # define le32toh(x) LE_IN32(x)
  39. # define htobe64(x) BE_64(x)
  40. # define htole64(x) LE_64(x)
  41. # define be64toh(x) BE_IN64(x)
  42. # define le64toh(x) LE_IN64(x)
  43. #else // *BSD
  44. # include <sys/endian.h>
  45. #endif
  46. #endif // YRMCDS_PORTABILITY_H_INCLUDED