]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Added generic functions for unaligned data access.
authorMartin Mares <mj@ucw.cz>
Tue, 26 May 1998 21:38:06 +0000 (21:38 +0000)
committerMartin Mares <mj@ucw.cz>
Tue, 26 May 1998 21:38:06 +0000 (21:38 +0000)
lib/unaligned.h

index 29fcee99f55940a5af6155560292a39453770cf6..53e32e5de83c67050925bf31751916e9cfa5a5be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Unaligned Data Accesses
+ *     Unaligned Data Accesses -- Generic Version
  *
  *     (c) 1998 Martin Mares <mj@ucw.cz>
  *
@@ -9,4 +9,34 @@
 #ifndef _BIRD_UNALIGNED_H_
 #define _BIRD_UNALIGNED_H_
 
+#if CPU_NEEDS_ALIGN_WORD != 1 || CPU_NEEDS_ALIGN_LONG != 1
+#include <string.h>
+#endif
+
+#if CPU_NEEDS_ALIGN_WORD == 1
+#define unaligned_u16(p) (*((u16 *)(p)))
+#else
+static inline u16
+unaligned_u16(void *p)
+{
+  u16 x;
+
+  memcpy(&x, p, sizeof(x));
+  return x;
+}
+#endif
+
+#if CPU_NEEDS_ALIGN_LONG == 1
+#define unaligned_u32(p) (*((u32 *)(p)))
+#else
+static inline u32
+unaligned_u32(void *p)
+{
+  u32 x;
+
+  memcpy(&x, p, sizeof(x));
+  return x;
+}
+#endif
+
 #endif