From e5c42594e552173692ca0f4fb3abab821e5e7434 Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Mon, 28 Nov 2022 14:47:46 +0000 Subject: [PATCH] Add byte order detection macro Signed-off-by: Dave Rodgman --- library/alignment.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/alignment.h b/library/alignment.h index 3539c9175e..3f8926e291 100644 --- a/library/alignment.h +++ b/library/alignment.h @@ -120,6 +120,13 @@ inline void mbedtls_put_unaligned_uint64( void *p, uint64_t x ) #define MBEDTLS_BYTE_6( x ) ( (uint8_t) ( ( ( x ) >> 48 ) & 0xff ) ) #define MBEDTLS_BYTE_7( x ) ( (uint8_t) ( ( ( x ) >> 56 ) & 0xff ) ) +#if !defined(__BYTE_ORDER__) +static const uint16_t mbedtls_byte_order_detector = { 0x100 }; +#define MBEDTLS_IS_BIG_ENDIAN (*((unsigned char *) (&mbedtls_byte_order_detector)) == 0x01) +#else +#define MBEDTLS_IS_BIG_ENDIAN ((__BYTE_ORDER__) == (__ORDER_BIG_ENDIAN__)) +#endif /* !defined(__BYTE_ORDER__) */ + /** * Get the unsigned 32 bits integer corresponding to four bytes in * big-endian order (MSB first).