summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2005-01-20 18:14:19 +0000
committerMarcel Holtmann <marcel@holtmann.org>2005-01-20 18:14:19 +0000
commitef5f2b1b3adbc8509dc47a4c53f31e6e9f867d0b (patch)
tree603f8284b3a7bfa8d957e6659cf054b014861774
parent659be2ac5b9af82ecdc63907e2a463c712187543 (diff)
Use better way for unaligned access
-rw-r--r--include/bluetooth.h26
1 files 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 {