Skip to content

Commit

Permalink
ccan/endian.h: Only define __{BIG,LITTLE}_ENDIAN if undefined.
Browse files Browse the repository at this point in the history
When both endian.h and ccan/endian/endian.h are included, we can have
__{BIG,LITTLE}_ENDIAN redefined when compiling with clang on FreeBSD.
Clang and gcc have moved to a predefine for endian orders. glibc defines
these the same as they are defied here, but that's an unsafe assumption
to make. Instead, only define them when __LITTLE_ENDIAN not defined as a
fallback to when the host does not define them in the standard system
headers.

Signed-off-by: Warner Losh <imp@bsdimp.com>
  • Loading branch information
bsdimp committed May 6, 2024
1 parent 80c5cf2 commit d9301dd
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ccan/ccan/endian/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ static inline uint64_t bswap_64(uint64_t val)
#endif

/* Needed for Glibc like endiness check */
#ifndef __LITTLE_ENDIAN
#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321
#endif

/* Sanity check the defines. We don't handle weird endianness. */
#if !HAVE_LITTLE_ENDIAN && !HAVE_BIG_ENDIAN
Expand Down

0 comments on commit d9301dd

Please sign in to comment.