endian.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (C) 1992-2020 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, see
  13. <https://www.gnu.org/licenses/>. */
  14. #ifndef _ENDIAN_H
  15. #define _ENDIAN_H 1
  16. #include <features.h>
  17. /* Get the definitions of __*_ENDIAN, __BYTE_ORDER, and __FLOAT_WORD_ORDER. */
  18. #include <bits/endian.h>
  19. #ifdef __USE_MISC
  20. # define LITTLE_ENDIAN __LITTLE_ENDIAN
  21. # define BIG_ENDIAN __BIG_ENDIAN
  22. # define PDP_ENDIAN __PDP_ENDIAN
  23. # define BYTE_ORDER __BYTE_ORDER
  24. #endif
  25. #if defined __USE_MISC && !defined __ASSEMBLER__
  26. /* Conversion interfaces. */
  27. # include <bits/byteswap.h>
  28. # include <bits/uintn-identity.h>
  29. # if __BYTE_ORDER == __LITTLE_ENDIAN
  30. # define htobe16(x) __bswap_16 (x)
  31. # define htole16(x) __uint16_identity (x)
  32. # define be16toh(x) __bswap_16 (x)
  33. # define le16toh(x) __uint16_identity (x)
  34. # define htobe32(x) __bswap_32 (x)
  35. # define htole32(x) __uint32_identity (x)
  36. # define be32toh(x) __bswap_32 (x)
  37. # define le32toh(x) __uint32_identity (x)
  38. # define htobe64(x) __bswap_64 (x)
  39. # define htole64(x) __uint64_identity (x)
  40. # define be64toh(x) __bswap_64 (x)
  41. # define le64toh(x) __uint64_identity (x)
  42. # else
  43. # define htobe16(x) __uint16_identity (x)
  44. # define htole16(x) __bswap_16 (x)
  45. # define be16toh(x) __uint16_identity (x)
  46. # define le16toh(x) __bswap_16 (x)
  47. # define htobe32(x) __uint32_identity (x)
  48. # define htole32(x) __bswap_32 (x)
  49. # define be32toh(x) __uint32_identity (x)
  50. # define le32toh(x) __bswap_32 (x)
  51. # define htobe64(x) __uint64_identity (x)
  52. # define htole64(x) __bswap_64 (x)
  53. # define be64toh(x) __uint64_identity (x)
  54. # define le64toh(x) __bswap_64 (x)
  55. # endif
  56. #endif
  57. #endif /* endian.h */