From 4d2b3561fc2b94fd9506b68a760365839c849a70 Mon Sep 17 00:00:00 2001
From: Leorize <alaviss@users.noreply.github.com>
Date: Thu, 14 Dec 2017 07:22:34 +0700
Subject: [PATCH 2/5] libs/bsd: add be64dec(3) and be64enc(3)
---
headers/compatibility/bsd/endian.h | 39 ++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/headers/compatibility/bsd/endian.h b/headers/compatibility/bsd/endian.h
index 07f564a1..44381ced 100644
a
|
b
|
|
13 | 13 | |
14 | 14 | #include <config/HaikuConfig.h> |
15 | 15 | #include <support/ByteOrder.h> |
| 16 | #include <support/SupportDefs.h> |
16 | 17 | |
17 | 18 | #ifdef __cplusplus |
18 | 19 | extern "C" { |
… |
… |
extern "C" {
|
59 | 60 | #define le64toh(x) bswap64((x)) |
60 | 61 | #endif /* BYTE_ORDER == LITTLE_ENDIAN */ |
61 | 62 | |
| 63 | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ |
| 64 | |
| 65 | static __inline uint32_t |
| 66 | be32dec(const void *pp) |
| 67 | { |
| 68 | uint8_t const *p = (uint8_t const *)pp; |
| 69 | |
| 70 | return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); |
| 71 | } |
| 72 | |
| 73 | static __inline uint64_t |
| 74 | be64dec(const void *pp) |
| 75 | { |
| 76 | uint8_t const *p = (uint8_t const *)pp; |
| 77 | |
| 78 | return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); |
| 79 | } |
| 80 | |
| 81 | static __inline void |
| 82 | be32enc(void *pp, uint32_t u) |
| 83 | { |
| 84 | uint8_t *p = (uint8_t *)pp; |
| 85 | |
| 86 | p[0] = (u >> 24) & 0xff; |
| 87 | p[1] = (u >> 16) & 0xff; |
| 88 | p[2] = (u >> 8) & 0xff; |
| 89 | p[3] = u & 0xff; |
| 90 | } |
| 91 | |
| 92 | static __inline void |
| 93 | be64enc(void *pp, uint64_t u) |
| 94 | { |
| 95 | uint8_t *p = (uint8_t *)pp; |
| 96 | |
| 97 | be32enc(p, (uint32_t)(u >> 32)); |
| 98 | be32enc(p + 4, (uint32_t)(u & 0xffffffffU)); |
| 99 | } |
| 100 | |
62 | 101 | #ifdef __cplusplus |
63 | 102 | } |
64 | 103 | #endif |