endian.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* Copyright (C) 1992, 1996, 1997, 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef _ENDIAN_H
  16. #define _ENDIAN_H 1
  17. #include <features.h>
  18. /* Definitions for byte order, according to significance of bytes,
  19. from low addresses to high addresses. The value is what you get by
  20. putting '4' in the most significant byte, '3' in the second most
  21. significant byte, '2' in the second least significant byte, and '1'
  22. in the least significant byte, and then writing down one digit for
  23. each byte, starting with the byte at the lowest address at the left,
  24. and proceeding to the byte with the highest address at the right. */
  25. #define __LITTLE_ENDIAN 1234
  26. #define __BIG_ENDIAN 4321
  27. #define __PDP_ENDIAN 3412
  28. /* This file defines `__BYTE_ORDER' for the particular machine. */
  29. #include <bits/endian.h>
  30. /* Some machines may need to use a different endianness for floating point
  31. values. */
  32. #ifndef __FLOAT_WORD_ORDER
  33. # define __FLOAT_WORD_ORDER __BYTE_ORDER
  34. #endif
  35. #ifdef __USE_BSD
  36. # define LITTLE_ENDIAN __LITTLE_ENDIAN
  37. # define BIG_ENDIAN __BIG_ENDIAN
  38. # define PDP_ENDIAN __PDP_ENDIAN
  39. # define BYTE_ORDER __BYTE_ORDER
  40. #endif
  41. #if __BYTE_ORDER == __LITTLE_ENDIAN
  42. # define __LONG_LONG_PAIR(HI, LO) LO, HI
  43. #elif __BYTE_ORDER == __BIG_ENDIAN
  44. # define __LONG_LONG_PAIR(HI, LO) HI, LO
  45. #endif
  46. #ifdef __USE_BSD
  47. /* Conversion interfaces. */
  48. # include <byteswap.h>
  49. # if __BYTE_ORDER == __LITTLE_ENDIAN
  50. # define htobe16(x) __bswap_16 (x)
  51. # define htole16(x) (x)
  52. # define be16toh(x) __bswap_16 (x)
  53. # define le16toh(x) (x)
  54. # define htobe32(x) __bswap_32 (x)
  55. # define htole32(x) (x)
  56. # define be32toh(x) __bswap_32 (x)
  57. # define le32toh(x) (x)
  58. # define htobe64(x) __bswap_64 (x)
  59. # define htole64(x) (x)
  60. # define be64toh(x) __bswap_64 (x)
  61. # define le64toh(x) (x)
  62. # else
  63. # define htobe16(x) (x)
  64. # define htole16(x) __bswap_16 (x)
  65. # define be16toh(x) (x)
  66. # define le16toh(x) __bswap_16 (x)
  67. # define htobe32(x) (x)
  68. # define htole32(x) __bswap_32 (x)
  69. # define be32toh(x) (x)
  70. # define le32toh(x) __bswap_32 (x)
  71. # define htobe64(x) (x)
  72. # define htole64(x) __bswap_64 (x)
  73. # define be64toh(x) (x)
  74. # define le64toh(x) __bswap_64 (x)
  75. # endif
  76. #endif
  77. #endif /* endian.h */