Add a new get_be64 macro to enable 64 bit endian conversions on memory
that may or may not be aligned.

Signed-off-by: Ben Peart <benpe...@microsoft.com>
---
 compat/bswap.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/compat/bswap.h b/compat/bswap.h
index d47c003544..f89fe7f4b5 100644
--- a/compat/bswap.h
+++ b/compat/bswap.h
@@ -158,6 +158,7 @@ static inline uint64_t git_bswap64(uint64_t x)
 
 #define get_be16(p)    ntohs(*(unsigned short *)(p))
 #define get_be32(p)    ntohl(*(unsigned int *)(p))
+#define get_be64(p)    ntohll(*(uint64_t *)(p))
 #define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
 
 #else
@@ -170,6 +171,9 @@ static inline uint64_t git_bswap64(uint64_t x)
        (*((unsigned char *)(p) + 1) << 16) | \
        (*((unsigned char *)(p) + 2) <<  8) | \
        (*((unsigned char *)(p) + 3) <<  0) )
+#define get_be64(p)    ( \
+       ((uint64_t)get_be32((unsigned char *)(p) + 0) << 32) | \
+       ((uint64_t)get_be32((unsigned char *)(p) + 4) <<  0)
 #define put_be32(p, v) do { \
        unsigned int __v = (v); \
        *((unsigned char *)(p) + 0) = __v >> 24; \
-- 
2.13.0.windows.1.9.gc201c67b71

Reply via email to