summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Peart <peartben@gmail.com>2017-05-18 16:13:28 -0400
committerJunio C Hamano <gitster@pobox.com>2017-05-20 18:28:07 +0900
commit72378592cabfe0241e1f1993bee76757e829f300 (patch)
tree01130297e7ca2b087f0c89ec5166f31054c1e6ae
parentb06d3643105c8758ed019125a4399cb7efdcce2c (diff)
downloadgit-72378592cabfe0241e1f1993bee76757e829f300.tar.gz
bswap: add 64 bit endianness helper get_be64
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 <benpeart@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--compat/bswap.h4
1 files changed, 4 insertions, 0 deletions
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; \