From: Nathan Rossi <nathan.rossi@xilinx.com>
Date: Tue, 27 Jan 2015 14:59:35 +1000
Subject: [PATCH] Generic arch dectection for padding defines

When available use the GNU C defines for endian and bitwidth to
determine the padding required. This reduces the need to define the
padding selection for every architecture.

Signed-off-by: Nathan Rossi <nathan.rossi@xilinx.com>
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Upstream-Status: Backport
---
 src/libaio.h | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/libaio.h b/src/libaio.h
index 1223146..4a4e0f5 100644
--- a/src/libaio.h
+++ b/src/libaio.h
@@ -52,14 +52,18 @@ typedef enum io_iocb_cmd {
 /* little endian, 32 bits */
 #if defined(__i386__) || (defined(__arm__) && !defined(__ARMEB__)) || \
     defined(__sh__) || defined(__bfin__) || defined(__MIPSEL__) || \
-    defined(__cris__)
+    defined(__cris__) || \
+    (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
+         __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 4)
 #define PADDED(x, y)	x; unsigned y
 #define PADDEDptr(x, y)	x; unsigned y
 #define PADDEDul(x, y)	unsigned long x; unsigned y
 
 /* little endian, 64 bits */
 #elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__) || \
-      (defined(__aarch64__) && defined(__AARCH64EL__))
+      (defined(__aarch64__) && defined(__AARCH64EL__)) || \
+      (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
+          __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_LONG__ == 8)
 #define PADDED(x, y)	x, y
 #define PADDEDptr(x, y)	x
 #define PADDEDul(x, y)	unsigned long x
@@ -67,7 +71,9 @@ typedef enum io_iocb_cmd {
 /* big endian, 64 bits */
 #elif defined(__powerpc64__) || defined(__s390x__) || \
       (defined(__sparc__) && defined(__arch64__)) || \
-      (defined(__aarch64__) && defined(__AARCH64EB__))
+      (defined(__aarch64__) && defined(__AARCH64EB__)) || \
+      (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
+           __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 8)
 #define PADDED(x, y)	unsigned y; x
 #define PADDEDptr(x,y)	x
 #define PADDEDul(x, y)	unsigned long x
@@ -76,7 +82,9 @@ typedef enum io_iocb_cmd {
 #elif defined(__PPC__) || defined(__s390__) || \
       (defined(__arm__) && defined(__ARMEB__)) || \
       defined(__sparc__) || defined(__MIPSEB__) || defined(__m68k__) || \
-      defined(__hppa__) || defined(__frv__) || defined(__avr32__)
+      defined(__hppa__) || defined(__frv__) || defined(__avr32__) || \
+      (defined(__GNUC__) && defined(__BYTE_ORDER__) && \
+           __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ && __SIZEOF_LONG__ == 4)
 #define PADDED(x, y)	unsigned y; x
 #define PADDEDptr(x, y)	unsigned y; x
 #define PADDEDul(x, y)	unsigned y; unsigned long x
-- 
2.1.1

