Show More
@@ -5,6 +5,18 b'' | |||||
5 |
|
5 | |||
6 | #include "compat.h" |
|
6 | #include "compat.h" | |
7 |
|
7 | |||
|
8 | /* Reads a 64 bit integer from big-endian bytes. Assumes that the data is long | |||
|
9 | enough */ | |||
|
10 | static inline uint64_t getbe64(const char *c) | |||
|
11 | { | |||
|
12 | const unsigned char *d = (const unsigned char *)c; | |||
|
13 | ||||
|
14 | return ((((uint64_t)d[0]) << 56) | (((uint64_t)d[1]) << 48) | | |||
|
15 | (((uint64_t)d[2]) << 40) | (((uint64_t)d[3]) << 32) | | |||
|
16 | (((uint64_t)d[4]) << 24) | (((uint64_t)d[5]) << 16) | | |||
|
17 | (((uint64_t)d[6]) << 8) | (d[7])); | |||
|
18 | } | |||
|
19 | ||||
8 | static inline uint32_t getbe32(const char *c) |
|
20 | static inline uint32_t getbe32(const char *c) | |
9 | { |
|
21 | { | |
10 | const unsigned char *d = (const unsigned char *)c; |
|
22 | const unsigned char *d = (const unsigned char *)c; | |
@@ -27,6 +39,20 b' static inline uint16_t getbeuint16(const' | |||||
27 | return ((d[0] << 8) | (d[1])); |
|
39 | return ((d[0] << 8) | (d[1])); | |
28 | } |
|
40 | } | |
29 |
|
41 | |||
|
42 | /* Writes a 64 bit integer to bytes in a big-endian format. | |||
|
43 | Assumes that the buffer is long enough */ | |||
|
44 | static inline void putbe64(uint64_t x, char *c) | |||
|
45 | { | |||
|
46 | c[0] = (x >> 56) & 0xff; | |||
|
47 | c[1] = (x >> 48) & 0xff; | |||
|
48 | c[2] = (x >> 40) & 0xff; | |||
|
49 | c[3] = (x >> 32) & 0xff; | |||
|
50 | c[4] = (x >> 24) & 0xff; | |||
|
51 | c[5] = (x >> 16) & 0xff; | |||
|
52 | c[6] = (x >> 8) & 0xff; | |||
|
53 | c[7] = (x)&0xff; | |||
|
54 | } | |||
|
55 | ||||
30 | static inline void putbe32(uint32_t x, char *c) |
|
56 | static inline void putbe32(uint32_t x, char *c) | |
31 | { |
|
57 | { | |
32 | c[0] = (x >> 24) & 0xff; |
|
58 | c[0] = (x >> 24) & 0xff; |
General Comments 0
You need to be logged in to leave comments.
Login now