mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
sys/libc/endian.h: fix compilation with older newlib
Older versions of newlib already provide the magic endian numbers via `machine/endian.h`, which may be indirectly included. This changes the header to only provide the macros if the are not provided otherwise. For sanity, it checks if the values are indeed the expected magic numbers, even if provided from other sources.
This commit is contained in:
parent
0d01356c9c
commit
10e896390d
@ -69,10 +69,26 @@ uint64_t le64toh(uint64_t little_endian_64bits);/**< little endian to host, 64 b
|
||||
|
||||
#else /* DOXYGEN */
|
||||
|
||||
#define LITTLE_ENDIAN 1234
|
||||
#define BIG_ENDIAN 4321
|
||||
#define PDP_ENDIAN 3412
|
||||
#define BYTE_ORDER __BYTE_ORDER__
|
||||
/* Depending on the version of newlib used, newlib may provide them indirectly
|
||||
* as well. We don't want to redefine them in this case */
|
||||
#ifndef LITTLE_ENDIAN
|
||||
# define LITTLE_ENDIAN 1234
|
||||
#endif
|
||||
#ifndef BIG_ENDIAN
|
||||
# define BIG_ENDIAN 4321
|
||||
#endif
|
||||
#ifndef PDP_ENDIAN
|
||||
# define PDP_ENDIAN 3412
|
||||
#endif
|
||||
#ifndef BYTE_ORDER
|
||||
# define BYTE_ORDER __BYTE_ORDER__
|
||||
#endif
|
||||
|
||||
/* But to avoid lots of pain in the ass: Let's at least make sure everyone
|
||||
* agrees on what magic number is what */
|
||||
#if (LITTLE_ENDIAN != 1234) || (BIG_ENDIAN != 4321) || (PDP_ENDIAN != 3412)
|
||||
# error "Mismatching magic numbers to refer to endianness"
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define htobe16(_x) __builtin_bswap16(_x)
|
||||
|
Loading…
Reference in New Issue
Block a user