Skip to content

Commit

Permalink
Merge pull request #20985 from benpicco/picolibc-endian.h
Browse files Browse the repository at this point in the history
sys/endian: fix build with picolibc
  • Loading branch information
maribu authored Nov 13, 2024
2 parents 03b6122 + 3e8c7d0 commit fe62143
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions sys/include/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,79 @@ uint64_t le64toh(uint64_t little_endian_64bits);/**< little endian to host, 64 b
#endif

#if BYTE_ORDER == LITTLE_ENDIAN
# ifndef htobe16
# define htobe16(_x) __builtin_bswap16(_x)
# endif
# ifndef htole16
# define htole16(_x) ((uint16_t)(_x))
# endif
# ifndef be16toh
# define be16toh(_x) __builtin_bswap16(_x)
# endif
# ifndef le16toh
# define le16toh(_x) ((uint16_t)(_x))
# endif
# ifndef htobe32
# define htobe32(_x) __builtin_bswap32(_x)
# endif
# ifndef htole32
# define htole32(_x) ((uint32_t)(_x))
# endif
# ifndef be32toh
# define be32toh(_x) __builtin_bswap32(_x)
# endif
# ifndef le32toh
# define le32toh(_x) ((uint32_t)(_x))
# endif
# ifndef htobe64
# define htobe64(_x) __builtin_bswap64(_x)
# endif
# ifndef htole64
# define htole64(_x) ((uint64_t)(_x))
# endif
# ifndef be64toh
# define be64toh(_x) __builtin_bswap64(_x)
# endif
# ifndef le64toh
# define le64toh(_x) ((uint64_t)(_x))
# endif
#elif BYTE_ORDER == BIG_ENDIAN
# ifndef htole16
# define htole16(_x) __builtin_bswap16(_x)
# endif
# ifndef htobe16
# define htobe16(_x) ((uint16_t)(_x))
# endif
# ifndef le16toh
# define le16toh(_x) __builtin_bswap16(_x)
# endif
# ifndef be16toh
# define be16toh(_x) ((uint16_t)(_x))
# endif
# ifndef htole32
# define htole32(_x) __builtin_bswap32(_x)
# endif
# ifndef htobe32
# define htobe32(_x) ((uint32_t)(_x))
# endif
# ifndef le32toh
# define le32toh(_x) __builtin_bswap32(_x)
# endif
# ifndef be32toh
# define be32toh(_x) ((uint32_t)(_x))
# endif
# ifndef htole64
# define htole64(_x) __builtin_bswap64(_x)
# endif
# ifndef htobe64
# define htobe64(_x) ((uint64_t)(_x))
# endif
# ifndef le64toh
# define le64toh(_x) __builtin_bswap64(_x)
# endif
# ifndef be64toh
# define be64toh(_x) ((uint64_t)(_x))
# endif
#else
# error "Byte order not supported"
#endif
Expand Down

0 comments on commit fe62143

Please sign in to comment.