summaryrefslogtreecommitdiff
path: root/lib/unaligned.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unaligned.h')
-rw-r--r--lib/unaligned.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/unaligned.h b/lib/unaligned.h
index dc777fbf..0da1fdb4 100644
--- a/lib/unaligned.h
+++ b/lib/unaligned.h
@@ -17,6 +17,7 @@
* if possible.
*/
+#include "sysdep/unix/endian.h"
#include "lib/string.h"
static inline u16
@@ -28,6 +29,13 @@ get_u16(const void *p)
}
static inline u32
+get_u24(const void *P)
+{
+ const byte *p = P;
+ return (p[0] << 16) + (p[1] << 8) + p[2];
+}
+
+static inline u32
get_u32(const void *p)
{
u32 x;
@@ -52,6 +60,13 @@ put_u16(void *p, u16 x)
}
static inline void
+put_u24(void *p, u32 x)
+{
+ x = htonl(x);
+ memcpy(p, ((char *) &x) + 1, 3);
+}
+
+static inline void
put_u32(void *p, u32 x)
{
x = htonl(x);
@@ -68,4 +83,22 @@ put_u64(void *p, u64 x)
memcpy(p+4, &xl, 4);
}
+static inline void
+get_u32s(const void *p, u32 *x, int n)
+{
+ int i;
+ memcpy(x, p, 4*n);
+ for (i = 0; i < n; i++)
+ x[i] = ntohl(x[i]);
+}
+
+static inline void
+put_u32s(void *p, const u32 *x, int n)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ put_u32((byte *) p + 4*i, x[i]);
+}
+
+
#endif