Commit Graph

5 Commits

Author SHA1 Message Date
Bowgo Tsai 41d8a576ec <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
2019-09-18 13:06:45 +08:00
Colin Cross 888c1b9de5 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
2019-08-13 15:27:00 -07:00
Elliott Hughes f86ea02de6 Use as much of the macOS endian support as we can.
Turns out that although there's no <endian.h> or <sys/endian.h>, there
are <machine/endian.h> and <sys/_endian.h>, and they're included by
other system headers such as <dirent.h>.

Reuse the contents of <sys/_endian.h> here for better interop.

Bug: http://b/139203733
Test: treehugger
Change-Id: Ic0e9bfa1a5b56d05e9e542839d237b6ceae4aa8c
2019-08-12 12:11:42 -07:00
Elliott Hughes 4d8bbc6f8b libbase: switch to #pragma once.
Bug: N/A
Test: builds
Change-Id: I125498ac4257ac4e901c6f2a5f1bfac1432d859d
2018-06-26 17:17:41 -07:00
Elliott Hughes 1dbd976200 Add cross-platform <android-base/endian.h>.
Bionic has <sys/endian.h>, glibc <endian.h>, and macOS and Windows have
nothing. This has often been annoying.

Bug: N/A
Test: new tests
Change-Id: I2a40c570df6a9bb30607ace1af653265938cc4b8
2017-02-24 14:03:36 -08:00