<android-base/endian.h>: fix interoperability issue

<winsock2.h> has defined htonl(), ntohl(), htons() and ntohs() with
different return type that cannot be replaced by those macro definitions
in <android-base/endian.h>.

Includes <winsock2.h> first to prevent them from being replaced.
Then defines the macro later so we don't need to call into DLL
when using those functions.

Bug: 139639521
Test: m libbase_test && wine out/host/windows-x86/nativetest64/libbase_test/libbase_test64.exe
Test: m checkbuild
Change-Id: I672f23a31c6800df10e04d36695d446bca4c91e9
This commit is contained in:
Bowgo Tsai 2019-09-17 22:24:38 +08:00
parent a550e7f412
commit 41d8a576ec

View file

@ -51,8 +51,10 @@
/* macOS has some of the basics. */
#include <sys/_endian.h>
#else
/* Windows has even less. */
/* Windows has some of the basics as well. */
#include <sys/param.h>
#include <winsock2.h>
/* winsock2.h *must* be included before the following four macros. */
#define htons(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohs(x) __builtin_bswap16(x)