[v2,2/2] time: Add padding for the timespec if required

Message ID 20190927234133.1046-2-alistair.francis@wdc.com
State New, archived
Headers

Commit Message

Alistair Francis Sept. 27, 2019, 11:41 p.m. UTC
  If we are running on a 32-bit system with a 64-bit time_t we need to
ensure there is padding around the tv_nsec variable. This is requried as
the timespec is #defined to the __timespec64 struct.

2019-09-20  Alistair Francis  <alistair.francis@wdc.com>

	* time/bits/types/struct_timespec.h: Add padding for the timespec if
	required.
---
v2:
 - Fix style issues

 time/bits/types/struct_timespec.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
  

Comments

Joseph Myers Sept. 30, 2019, 3:26 p.m. UTC | #1
On Fri, 27 Sep 2019, Alistair Francis wrote:

> If we are running on a 32-bit system with a 64-bit time_t we need to
> ensure there is padding around the tv_nsec variable. This is requried as
> the timespec is #defined to the __timespec64 struct.
> 
> 2019-09-20  Alistair Francis  <alistair.francis@wdc.com>
> 
> 	* time/bits/types/struct_timespec.h: Add padding for the timespec if
> 	required.
> ---
> v2:
>  - Fix style issues

This patch is OK once the endian changes are in.
  

Patch

diff --git a/time/bits/types/struct_timespec.h b/time/bits/types/struct_timespec.h
index 5b77c52b4f0..d11c69cfd32 100644
--- a/time/bits/types/struct_timespec.h
+++ b/time/bits/types/struct_timespec.h
@@ -3,13 +3,26 @@ 
 #define _STRUCT_TIMESPEC 1
 
 #include <bits/types.h>
+#include <bits/endian.h>
 
 /* POSIX.1b structure for a time value.  This is like a `struct timeval' but
    has nanoseconds instead of microseconds.  */
 struct timespec
 {
   __time_t tv_sec;		/* Seconds.  */
+#if __WORDSIZE == 64 \
+  || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64) \
+  || __TIMESIZE == 32
   __syscall_slong_t tv_nsec;	/* Nanoseconds.  */
+#else
+# if __BYTE_ORDER == __BIG_ENDIAN
+  int: 32;           /* Padding.  */
+  long int tv_nsec;  /* Nanoseconds.  */
+# else
+  long int tv_nsec;  /* Nanoseconds.  */
+  int: 32;           /* Padding.  */
+# endif
+#endif
 };
 
 #endif