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
This commit is contained in:
parent
53620ca1b1
commit
888c1b9de5
|
@ -18,6 +18,9 @@
|
|||
|
||||
/* A cross-platform equivalent of bionic's <sys/endian.h>. */
|
||||
|
||||
/* For __BIONIC__ and __GLIBC__ */
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#if defined(__BIONIC__)
|
||||
|
||||
#include <sys/endian.h>
|
||||
|
@ -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 <sys/_endian.h>
|
||||
#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 <sys/param.h>
|
||||
#define htons(x) __builtin_bswap16(x)
|
||||
#define htonl(x) __builtin_bswap32(x)
|
||||
#define ntohs(x) __builtin_bswap16(x)
|
||||
|
|
Loading…
Reference in New Issue