From 888c1b9de5c6529e15f18401a55866a7e4a5c50a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 13 Aug 2019 15:23:53 -0700 Subject: [PATCH] Fix more endian.h issues __BIONIC__ is defined in sys/cdefs.h, __GLIBC__ is defined in features.h (which is included from sys/cdefs.h). If sys/cdefs.h was not included before android-base/endian.h it was always falling back to the Windows definitions. mingw defines LITTLE_ENDIAN, BIG_ENDIAN and BYTE_ORDER in sys/params.h, use those definitions to avoid conflicts. glibc uses different names for letoh*, add compatibily #defines. Test: m checkbuild Change-Id: I0709a964cc8f20dd9fa4f03064cc67d97ae6c525 --- base/include/android-base/endian.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/base/include/android-base/endian.h b/base/include/android-base/endian.h index 10efaa3a8..2d0f614ea 100644 --- a/base/include/android-base/endian.h +++ b/base/include/android-base/endian.h @@ -18,6 +18,9 @@ /* A cross-platform equivalent of bionic's . */ +/* For __BIONIC__ and __GLIBC__ */ +#include + #if defined(__BIONIC__) #include @@ -38,6 +41,9 @@ #define betoh16(x) be16toh(x) #define betoh32(x) be32toh(x) #define betoh64(x) be64toh(x) +#define letoh16(x) le16toh(x) +#define letoh32(x) le32toh(x) +#define letoh64(x) le64toh(x) #else @@ -45,10 +51,8 @@ /* macOS has some of the basics. */ #include #else -/* Windows really has nothing. */ -#define LITTLE_ENDIAN __LITTLE_ENDIAN -#define BIG_ENDIAN __BIG_ENDIAN -#define BYTE_ORDER __BYTE_ORDER +/* Windows has even less. */ +#include #define htons(x) __builtin_bswap16(x) #define htonl(x) __builtin_bswap32(x) #define ntohs(x) __builtin_bswap16(x)