[1/3] endian.h: introduce __type3264() macro
diff mbox

Message ID 1470304959-9944-2-git-send-email-ynorov@caviumnetworks.com
State New
Headers show

Commit Message

Yury Norov Aug. 4, 2016, 10:02 a.m. UTC
__type3264() declares structure field that has different size
in 32- and 64-bit ABIs with paddings where needed, so final
layout becomes identical. This macro is used in __field64(),
and in next patch of this series to declare struct timestamp
in sysdeps/unix/sysv/linux/generic/bits/stat.h and
sysdeps/unix/sysv/linux/generic/bits/statfs.h

	* string/endian.h: introduce __type3264() macro.
	* sysdeps/unix/sysv/linux/generic/bits/stat.h: use __type3264() in __field 64().
	* sysdeps/unix/sysv/linux/generic/bits/statfs.h: Likewise.

Signed-off-by: Yury Norov <ynorov@caviumnetworks.com>
---
 string/endian.h                               | 12 ++++++++++++
 sysdeps/unix/sysv/linux/generic/bits/stat.h   |  9 ++-------
 sysdeps/unix/sysv/linux/generic/bits/statfs.h |  8 +-------
 3 files changed, 15 insertions(+), 14 deletions(-)

Patch
diff mbox

diff --git a/string/endian.h b/string/endian.h
index b13ddaa..09fb0dd 100644
--- a/string/endian.h
+++ b/string/endian.h
@@ -54,6 +54,18 @@ 
 # define __LONG_LONG_PAIR(HI, LO) HI, LO
 #endif
 
+/* Declare structure field that has different size
+   in 32- and 64-bit ABIs with paddings where needed,
+   so final layout becomes identical.  */
+#if __WORDSIZE == 32
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+#  define __type3264(type, name) type name __attribute__((__aligned__ (__alignof__ (long long)))); type __##name##_pad
+# else
+#  define __type3264(type, name) type __##name##_pad __attribute__((__aligned__ (__alignof__ (long long)))); type name
+# endif
+#else /* __WORDSIZE == 64.  */
+# define __type3264(type, name) type name
+#endif
 
 #if defined __USE_MISC && !defined __ASSEMBLER__
 /* Conversion interfaces.  */
diff --git a/sysdeps/unix/sysv/linux/generic/bits/stat.h b/sysdeps/unix/sysv/linux/generic/bits/stat.h
index dd8d799..8e3f745 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/stat.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/stat.h
@@ -24,6 +24,7 @@ 
 #define _BITS_STAT_H	1
 
 #include <endian.h>
+#include <bits/types.h>
 #include <bits/wordsize.h>
 
 /* 64-bit libc uses the kernel's 'struct stat', accessed via the
@@ -42,14 +43,8 @@ 
 
 #if defined __USE_FILE_OFFSET64
 # define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
-# define __field64(type, type64, name) type name
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# define __field64(type, type64, name) \
-  type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
 #else
-# define __field64(type, type64, name) \
-  int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
+# define __field64(type, type64, name) __type3264 (type, name)
 #endif
 
 struct stat
diff --git a/sysdeps/unix/sysv/linux/generic/bits/statfs.h b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
index 7d5aa2d..96629ac 100644
--- a/sysdeps/unix/sysv/linux/generic/bits/statfs.h
+++ b/sysdeps/unix/sysv/linux/generic/bits/statfs.h
@@ -34,14 +34,8 @@ 
 
 #if defined __USE_FILE_OFFSET64
 # define __field64(type, type64, name) type64 name
-#elif __WORDSIZE == 64
-# define __field64(type, type64, name) type name
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-# define __field64(type, type64, name) \
-  type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
 #else
-# define __field64(type, type64, name) \
-  int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
+# define __field64(type, type64, name) __type3264 (type, name)
 #endif
 
 struct statfs