/* * unaligned.h * * Inline functions for unaligned memory accesses. * * The author dedicates this file to the public domain. * You can do whatever you want with this file. */ #ifndef _WIMLIB_UNALIGNED_H #define _WIMLIB_UNALIGNED_H #include "compiler.h" #include "endianness.h" #include "types.h" #define DEFINE_UNALIGNED_TYPE(type) \ struct type##_unaligned { \ type v; \ } _packed_attribute; \ \ static inline type \ load_##type##_unaligned(const void *p) \ { \ return ((const struct type##_unaligned *)p)->v; \ } \ \ static inline void \ store_##type##_unaligned(type val, void *p) \ { \ ((struct type##_unaligned *)p)->v = val; \ } DEFINE_UNALIGNED_TYPE(le16); DEFINE_UNALIGNED_TYPE(le32); DEFINE_UNALIGNED_TYPE(le64); DEFINE_UNALIGNED_TYPE(be32); DEFINE_UNALIGNED_TYPE(size_t); #endif /* _WIMLIB_UNALIGNED_H */