From 471de289672300e3d52df96b1e432ad49f33b222 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Fri, 8 Jul 2016 11:06:02 -0300 Subject: [PATCH] AP_Common: provide minimal byteswap.h and endian.h --- libraries/AP_Common/missing/byteswap.h | 24 ++++++++++++++++++++++++ libraries/AP_Common/missing/endian.h | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 libraries/AP_Common/missing/byteswap.h create mode 100644 libraries/AP_Common/missing/endian.h diff --git a/libraries/AP_Common/missing/byteswap.h b/libraries/AP_Common/missing/byteswap.h new file mode 100644 index 0000000000..8e014caa9c --- /dev/null +++ b/libraries/AP_Common/missing/byteswap.h @@ -0,0 +1,24 @@ +#if defined(HAVE_BYTESWAP_H) && HAVE_BYTESWAP_H +#include_next +#else + +#include + +/* minimal version defining only the macros we need in our codebase */ + +static inline uint16_t __bswap_16(uint16_t u) +{ + return (uint16_t) __builtin_bswap16(u); +} + +static inline uint32_t __bswap_32(uint32_t u) +{ + return (uint32_t) __builtin_bswap32(u); +} + +static inline uint64_t __bswap_64(uint64_t u) +{ + return (uint64_t) __builtin_bswap64(u); +} + +#endif diff --git a/libraries/AP_Common/missing/endian.h b/libraries/AP_Common/missing/endian.h new file mode 100644 index 0000000000..ed39019c0d --- /dev/null +++ b/libraries/AP_Common/missing/endian.h @@ -0,0 +1,16 @@ +#if defined(HAVE_ENDIAN_H) && HAVE_ENDIAN_H +#include_next +#else + +/* minimal version defining only the macros we need in our codebase */ + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 + +#ifdef __ARMEB__ +#define __BYTE_ORDER __BIG_ENDIAN +#else +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +#endif