4 * Inline functions for unaligned memory accesses.
6 * The author dedicates this file to the public domain.
7 * You can do whatever you want with this file.
10 #ifndef _WIMLIB_UNALIGNED_H
11 #define _WIMLIB_UNALIGNED_H
14 #include "endianness.h"
17 #define DEFINE_UNALIGNED_TYPE(type) \
18 struct type##_unaligned { \
20 } _packed_attribute; \
23 load_##type##_unaligned(const void *p) \
25 return ((const struct type##_unaligned *)p)->v; \
29 store_##type##_unaligned(type val, void *p) \
31 ((struct type##_unaligned *)p)->v = val; \
34 DEFINE_UNALIGNED_TYPE(le16);
35 DEFINE_UNALIGNED_TYPE(le32);
36 DEFINE_UNALIGNED_TYPE(le64);
37 DEFINE_UNALIGNED_TYPE(be32);
38 DEFINE_UNALIGNED_TYPE(size_t);
40 #endif /* _WIMLIB_UNALIGNED_H */