From 7261d9f12f9863beb5f09fde92174d0775b5c4eb Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 25 Jan 2014 01:19:18 -0800 Subject: [PATCH] shared: Add macros for unaligned access --- src/shared/util.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/shared/util.h b/src/shared/util.h index f0d236882..e93b7428a 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -55,6 +55,22 @@ #error "Unknown byte order" #endif +#define get_unaligned(ptr) \ +({ \ + struct __attribute__((packed)) { \ + typeof(*(ptr)) __v; \ + } *__p = (typeof(__p)) (ptr); \ + __p->__v; \ +}) + +#define put_unaligned(val, ptr) \ +do { \ + struct __attribute__((packed)) { \ + typeof(*(ptr)) __v; \ + } *__p = (typeof(__p)) (ptr); \ + __p->__v = (val); \ +} while (0) + #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) #define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u))) -- 2.47.3