[1/3] endian.h: introduce __type3264() macro
Commit Message
__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(-)
@@ -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. */
@@ -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
@@ -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