From a2dfbb3368ce0e998f774dd294383772651d1302 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 14 Jan 2017 04:40:03 +0100 Subject: Fix errors, blind-{to,from}-{video,image} works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/util/endian.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/util/endian.h (limited to 'src/util/endian.h') diff --git a/src/util/endian.h b/src/util/endian.h new file mode 100644 index 0000000..e6805b1 --- /dev/null +++ b/src/util/endian.h @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include + +#if defined(HAVE_ENDIAN_H) +# include +#elif defined(HAVE_SYS_ENDIAN_H) +# include +#endif + +#if !defined(HAVE_ENDIAN_H) && !defined(HAVE_SYS_ENDIAN_H) + +# if !defined(htole16) +# define htole16 blind_htole16 +static inline uint16_t +blind_htole16(uint16_t h) +{ + union { + unsigned char bytes[2]; + uint16_t value; + } d; + d.bytes[0] = h; + d.bytes[1] = h >> 8; + return d.value; +} +# endif + +# if !defined(le16toh) +# if defined(letoh16) +# define le16toh letoh16 +# else +# define le16toh blind_le16toh +static inline uint16_t +blind_le16toh(uint16_t le) +{ + unsigned char *bytes = (unsigned char *)≤ + return ((uint16_t)(bytes[1]) << 8) | (uint16_t)(bytes[0]); +} +# endif +# endif + +#elif defined(HAVE_OPENBSD_ENDIAN) +# define le16toh letoh16 +#endif -- cgit v1.2.3-70-g09d2