endian.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU Lesser General Public
  4. License version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details.
  6. Module Name:
  7. endian.h
  8. Abstract:
  9. This header contains definitions for the endian-ness of the machine.
  10. Author:
  11. Evan Green 16-Apr-2015
  12. --*/
  13. #ifndef _ENDIAN_H
  14. #define _ENDIAN_H
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. //
  22. // This machine is little endian.
  23. //
  24. #define BYTE_ORDER LITTLE_ENDIAN
  25. #define LITTLE_ENDIAN 1234
  26. #define BIG_ENDIAN 4321
  27. //
  28. // Define the byteswapping macros. For now, use the builtin, though this is
  29. // a little compiler-specific.
  30. //
  31. #define __byteswap16(_Value) __builtin_bswap16(_Value)
  32. #define __byteswap32(_Value) __builtin_bswap32(_Value)
  33. #define __byteswap64(_Value) __builtin_bswap64(_Value)
  34. #if BYTE_ORDER == LITTLE_ENDIAN
  35. #define htobe16(_Value) __byteswap16(_Value)
  36. #define htole16(_Value) (_Value)
  37. #define be16toh(_Value) __byteswap16(_Value)
  38. #define le16toh(_Value) (_Value)
  39. #define htobe32(_Value) __byteswap32(_Value)
  40. #define htole32(_Value) (_Value)
  41. #define be32toh(_Value) __byteswap32(_Value)
  42. #define le32toh(_Value) (_Value)
  43. #define htobe64(_Value) __byteswap64(_Value)
  44. #define htole64(_Value) (_Value)
  45. #define be64toh(_Value) __byteswap64(_Value)
  46. #define le64toh(_Value) (_Value)
  47. #else
  48. #define htobe16(_Value) (_Value)
  49. #define htole16(_Value) __byteswap16(_Value)
  50. #define be16toh(_Value) (_Value)
  51. #define le16toh(_Value) __byteswap16(_Value)
  52. #define htobe32(_Value) (_Value)
  53. #define htole32(_Value) __byteswap32(_Value)
  54. #define be32toh(_Value) (_Value)
  55. #define le32toh(_Value) __byteswap32(_Value)
  56. #define htobe64(_Value) (_Value)
  57. #define htole64(_Value) __byteswap64(_Value)
  58. #define be64toh(_Value) (_Value)
  59. #define le64toh(_Value) __byteswap64(_Value)
  60. #endif
  61. //
  62. // ------------------------------------------------------ Data Type Definitions
  63. //
  64. //
  65. // -------------------------------------------------------------------- Globals
  66. //
  67. //
  68. // -------------------------------------------------------- Function Prototypes
  69. //
  70. #endif