From ef5f2b1b3adbc8509dc47a4c53f31e6e9f867d0b Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Thu, 20 Jan 2005 18:14:19 +0000 Subject: Use better way for unaligned access --- include/bluetooth.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/include/bluetooth.h b/include/bluetooth.h index 80a2d169..142f6064 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -88,17 +88,21 @@ enum { #endif /* Bluetooth unaligned access */ -#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__s390__) || defined(__cris__) -#define bt_get_unaligned(ptr) (*(ptr)) -#define bt_put_unaligned(val, ptr) ((void)( *(ptr) = (val) )) -#else -#define bt_get_unaligned(ptr) \ - ({ __typeof__(*(ptr)) __tmp; memmove(&__tmp, (ptr), sizeof(*(ptr))); __tmp; }) -#define bt_put_unaligned(val, ptr) \ - ({ __typeof__(*(ptr)) __tmp = (val); \ - memmove((ptr), &__tmp, sizeof(*(ptr))); \ - (void)0; }) -#endif +#define bt_get_unaligned(ptr) \ +({ \ + struct __attribute__((packed)) { \ + typeof(*(ptr)) __v; \ + } *__p = (ptr); \ + __p->__v; \ +}) + +#define bt_put_unaligned(val, ptr) \ +do { \ + struct __attribute__((packed)) { \ + typeof(*(ptr)) __v; \ + } *__p = (ptr); \ + __p->__v = (val); \ +} while(0) /* BD Address */ typedef struct { -- cgit