diff options
author | Ben Peart <peartben@gmail.com> | 2017-05-18 16:13:28 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-20 18:28:07 +0900 |
commit | 72378592cabfe0241e1f1993bee76757e829f300 (patch) | |
tree | 01130297e7ca2b087f0c89ec5166f31054c1e6ae | |
parent | b06d3643105c8758ed019125a4399cb7efdcce2c (diff) | |
download | git-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.h | 4 |
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; \ |