cgpt_endian.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. #ifndef VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_
  6. #define VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_
  7. // Newer distros already have this. For those that don't, we add it here.
  8. #ifndef HAVE_MACOS
  9. #include <endian.h>
  10. #endif
  11. #ifndef le16toh
  12. #ifndef HAVE_MACOS
  13. # include <byteswap.h>
  14. #endif
  15. # if __BYTE_ORDER == __LITTLE_ENDIAN
  16. # define htobe16(x) __bswap_16 (x)
  17. # define htole16(x) (x)
  18. # define be16toh(x) __bswap_16 (x)
  19. # define le16toh(x) (x)
  20. # define htobe32(x) __bswap_32 (x)
  21. # define htole32(x) (x)
  22. # define be32toh(x) __bswap_32 (x)
  23. # define le32toh(x) (x)
  24. # define htobe64(x) __bswap_64 (x)
  25. # define htole64(x) (x)
  26. # define be64toh(x) __bswap_64 (x)
  27. # define le64toh(x) (x)
  28. # else
  29. # define htobe16(x) (x)
  30. # define htole16(x) __bswap_16 (x)
  31. # define be16toh(x) (x)
  32. # define le16toh(x) __bswap_16 (x)
  33. # define htobe32(x) (x)
  34. # define htole32(x) __bswap_32 (x)
  35. # define be32toh(x) (x)
  36. # define le32toh(x) __bswap_32 (x)
  37. # define htobe64(x) (x)
  38. # define htole64(x) __bswap_64 (x)
  39. # define be64toh(x) (x)
  40. # define le64toh(x) __bswap_64 (x)
  41. # endif
  42. #endif
  43. #endif // VBOOT_REFERENCE_UTILITY_CGPT_ENDIAN_H_