From 030e0af985c2d370a2f0274e9911b22b479c2439 Mon Sep 17 00:00:00 2001 From: Marian Buschsieweke Date: Fri, 14 Aug 2020 10:09:33 +0200 Subject: [PATCH] sys/unaligned: Add 64 bit version Add helper function to access `uint64_t` values with possibly unaligned pointers. --- sys/include/unaligned.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sys/include/unaligned.h b/sys/include/unaligned.h index ced46ac328..1ea3bce83f 100644 --- a/sys/include/unaligned.h +++ b/sys/include/unaligned.h @@ -53,6 +53,11 @@ typedef struct __attribute__((packed)) { uint32_t val; /**< value */ } uint32_una_t; +/** @brief Unaligned access helper struct (uint64_t version) */ +typedef struct __attribute__((packed)) { + uint64_t val; /**< value */ +} uint64_una_t; + /** * @brief Get uint16_t from possibly unaligned pointer * @@ -79,6 +84,19 @@ static inline uint32_t unaligned_get_u32(const void *ptr) return tmp->val; } +/** + * @brief Get uint64_t from possibly unaligned pointer + * + * @param[in] ptr pointer to read from + * + * @returns value read from @p ptr + */ +static inline uint64_t unaligned_get_u64(const void *ptr) +{ + const uint64_una_t *tmp = (const uint64_una_t *)ptr; + return tmp->val; +} + #ifdef __cplusplus } #endif