@@ -1,2 +1,36 @@
+#ifndef TOOLS_UNALIGNED_H
+#define TOOLS_UNALIGNED_H
+
+#include <stdint.h>
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+
+#ifdef __GNUC__
+
+struct _packed_u16_struct {
+ uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+ uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+ uint64_t v;
+} __attribute__((packed));
+
+#define TOOLS_UNALIGNED_GCC ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__)
+
+#else
+
+#define TOOLS_UNALIGNED_GCC 0
+
+#endif /* __GNUC__ */
+
#include <tools/unaligned/le_byteshift.h>
#include <tools/unaligned/be_byteshift.h>
+
+#endif /* TOOLS_UNALIGNED_H */
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BSWAP_H
#define TOOLS_BE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return __builtin_bswap16(get_unaligned_le16(_p));
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BYTESHIFT_H
#define TOOLS_BE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint8_t *p = _p;
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_DIRECT_H
#define TOOLS_BE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint16_t *p = _p;
@@ -1,12 +1,6 @@
#ifndef TOOLS_BE_ENDIAN_H
#define TOOLS_BE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return be16toh(get_unaligned_le16(_p));
@@ -1,20 +1,6 @@
#ifndef TOOLS_BE_STRUCT_H
#define TOOLS_BE_STRUCT_H
-#include <stdint.h>
-
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BSWAP_H
#define TOOLS_LE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return __builtin_bswap16(get_unaligned_be16(_p));
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BYTESHIFT_H
#define TOOLS_LE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint8_t *p = _p;
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_DIRECT_H
#define TOOLS_LE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint16_t *p = _p;
@@ -1,12 +1,6 @@
#ifndef TOOLS_LE_ENDIAN_H
#define TOOLS_LE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return le16toh(get_unaligned_be16(_p));
@@ -3,18 +3,6 @@
#include <stdint.h>
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
Move common includes and infrastructure into <tools/unaligned.h>. Signed-off-by: H. Peter Anvin <hpa@zytor.com> --- tools/include/tools/unaligned.h | 34 ++++++++++++++++++++++++++++ tools/include/tools/unaligned/be_bswap.h | 2 -- tools/include/tools/unaligned/be_byteshift.h | 2 -- tools/include/tools/unaligned/be_direct.h | 2 -- tools/include/tools/unaligned/be_endian.h | 6 ----- tools/include/tools/unaligned/be_struct.h | 14 ------------ tools/include/tools/unaligned/le_bswap.h | 2 -- tools/include/tools/unaligned/le_byteshift.h | 2 -- tools/include/tools/unaligned/le_direct.h | 2 -- tools/include/tools/unaligned/le_endian.h | 6 ----- tools/include/tools/unaligned/le_struct.h | 12 ---------- 11 files changed, 34 insertions(+), 50 deletions(-)