#ifndef __LOWSTAR_ENDIANNESS_H
#define __LOWSTAR_ENDIANNESS_H
#include <string.h>
#include <inttypes.h>
#if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) || defined(__GLIBC__)
# include <endian.h>
#elif defined(__APPLE__)
# include <libkern/OSByteOrder.h>
#define htole64 …
#define le64toh …
#define htobe64 …
#define be64toh …
#define htole16 …
#define le16toh …
#define htobe16 …
#define be16toh …
#define htole32 …
#define le32toh …
#define htobe32 …
#define be32toh …
#elif defined(__sun__)
# include <sys/byteorder.h>
#define htole64 …
#define le64toh …
#define htobe64 …
#define be64toh …
#define htole16 …
#define le16toh …
#define htobe16 …
#define be16toh …
#define htole32 …
#define le32toh …
#define htobe32 …
#define be32toh …
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
# include <sys/endian.h>
#elif defined(__OpenBSD__)
# include <endian.h>
#elif defined(_MSC_VER)
# include <stdlib.h>
#define htobe16 …
#define htole16 …
#define be16toh …
#define le16toh …
#define htobe32 …
#define htole32 …
#define be32toh …
#define le32toh …
#define htobe64 …
#define htole64 …
#define be64toh …
#define le64toh …
#elif (defined(_WIN32) || defined(_WIN64) || defined(__EMSCRIPTEN__)) && \
(defined(__GNUC__) || defined(__clang__))
#define htobe16 …
#define htole16 …
#define be16toh …
#define le16toh …
#define htobe32 …
#define htole32 …
#define be32toh …
#define le32toh …
#define htobe64 …
#define htole64 …
#define be64toh …
#define le64toh …
#elif (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) || defined(_AIX)
#define htobe32 …
#define be32toh …
#define htole32 …
#define le32toh …
#define htobe64 …
#define be64toh …
#define htole64 …
#define le64toh …
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htole32 …
#define le32toh …
#define htobe32 …
#define be32toh …
#define htole64 …
#define le64toh …
#define htobe64 …
#define be64toh …
#else
# error "Please define __BYTE_ORDER__!"
#endif
inline static uint16_t load16(uint8_t *b) { … }
inline static uint32_t load32(uint8_t *b) { … }
inline static uint64_t load64(uint8_t *b) { … }
inline static void store16(uint8_t *b, uint16_t i) { … }
inline static void store32(uint8_t *b, uint32_t i) { … }
inline static void store64(uint8_t *b, uint64_t i) { … }
#define load16_le(b) …
#define store16_le(b, i) …
#define load16_be(b) …
#define store16_be(b, i) …
#define load32_le(b) …
#define store32_le(b, i) …
#define load32_be(b) …
#define store32_be(b, i) …
#define load64_le(b) …
#define store64_le(b, i) …
#define load64_be(b) …
#define store64_be(b, i) …
#define load16_le0 …
#define store16_le0 …
#define load16_be0 …
#define store16_be0 …
#define load32_le0 …
#define store32_le0 …
#define load32_be0 …
#define store32_be0 …
#define load64_le0 …
#define store64_le0 …
#define load64_be0 …
#define store64_be0 …
#define load128_le0 …
#define store128_le0 …
#define load128_be0 …
#define store128_be0 …
#endif