#ifndef COMPAT_BSWAP_H
#define COMPAT_BSWAP_H
static inline uint32_t default_swab32(uint32_t val)
{ … }
static inline uint64_t default_bswap64(uint64_t val)
{ … }
#undef bswap32
#undef bswap64
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define bswap32 …
static inline uint32_t git_bswap32(uint32_t x)
{ … }
#define bswap64 …
#if defined(__x86_64__)
static inline uint64_t git_bswap64(uint64_t x)
{ … }
#else
static inline uint64_t git_bswap64(uint64_t x)
{
union { uint64_t i64; uint32_t i32[2]; } tmp, result;
if (__builtin_constant_p(x))
result.i64 = default_bswap64(x);
else {
tmp.i64 = x;
result.i32[0] = git_bswap32(tmp.i32[1]);
result.i32[1] = git_bswap32(tmp.i32[0]);
}
return result.i64;
}
#endif
#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM64))
#include <stdlib.h>
#define bswap32 …
#define bswap64 …
#endif
#if defined(bswap32)
#undef ntohl
#undef htonl
#define ntohl(x) …
#define htonl(x) …
#endif
#if defined(bswap64)
#undef ntohll
#undef htonll
#define ntohll(x) …
#define htonll(x) …
#else
#undef ntohll
#undef htonll
#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN)
#define GIT_BYTE_ORDER …
#define GIT_LITTLE_ENDIAN …
#define GIT_BIG_ENDIAN …
#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
#define GIT_BYTE_ORDER …
#define GIT_LITTLE_ENDIAN …
#define GIT_BIG_ENDIAN …
#else
#define GIT_BIG_ENDIAN …
#define GIT_LITTLE_ENDIAN …
# if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
#define GIT_BYTE_ORDER …
# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
#define GIT_BYTE_ORDER …
# elif defined(__THW_BIG_ENDIAN__) && !defined(__THW_LITTLE_ENDIAN__)
#define GIT_BYTE_ORDER …
# elif defined(__THW_LITTLE_ENDIAN__) && !defined(__THW_BIG_ENDIAN__)
#define GIT_BYTE_ORDER …
# else
# error "Cannot determine endianness"
# endif
#endif
#if GIT_BYTE_ORDER == GIT_BIG_ENDIAN
#define ntohll …
#define htonll …
#else
#define ntohll …
#define htonll …
#endif
#endif
static inline uint16_t get_be16(const void *ptr)
{ … }
static inline uint32_t get_be32(const void *ptr)
{ … }
static inline uint64_t get_be64(const void *ptr)
{ … }
static inline void put_be32(void *ptr, uint32_t value)
{ … }
static inline void put_be64(void *ptr, uint64_t value)
{ … }
#endif