Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
bswap: add 64 bit endianness helper get_be64
author
Ben Peart
<benpeart@microsoft.com>
Fri, 22 Sep 2017 16:35:37 +0000
(12:35 -0400)
committer
Junio C Hamano
<gitster@pobox.com>
Sun, 24 Sep 2017 01:39:37 +0000
(10:39 +0900)
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>
compat/bswap.h
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
6867272
)
diff --git
a/compat/bswap.h
b/compat/bswap.h
index 7d063e9e40a213ce378d90377a9ac2b1f04ddbe3..5078ce5eccfaf17620c21e0a7f7133b3badef3d3 100644
(file)
--- a/
compat/bswap.h
+++ b/
compat/bswap.h
@@
-158,7
+158,9
@@
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_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)
#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
+#define put_be64(p, v) do { *(uint64_t *)(p) = htonll(v); } while (0)
#else
#else
@@
-178,6
+180,13
@@
static inline uint32_t get_be32(const void *ptr)
(uint32_t)p[3] << 0;
}
(uint32_t)p[3] << 0;
}
+static inline uint64_t get_be64(const void *ptr)
+{
+ const unsigned char *p = ptr;
+ return (uint64_t)get_be32(&p[0]) << 32 |
+ (uint64_t)get_be32(&p[4]) << 0;
+}
+
static inline void put_be32(void *ptr, uint32_t value)
{
unsigned char *p = ptr;
static inline void put_be32(void *ptr, uint32_t value)
{
unsigned char *p = ptr;
@@
-187,4
+196,17
@@
static inline void put_be32(void *ptr, uint32_t value)
p[3] = value >> 0;
}
p[3] = value >> 0;
}
+static inline void put_be64(void *ptr, uint64_t value)
+{
+ unsigned char *p = ptr;
+ p[0] = value >> 56;
+ p[1] = value >> 48;
+ p[2] = value >> 40;
+ p[3] = value >> 32;
+ p[4] = value >> 24;
+ p[5] = value >> 16;
+ p[6] = value >> 8;
+ p[7] = value >> 0;
+}
+
#endif
#endif