summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlistair Francis <alistair.francis@wdc.com>2019-12-27 09:07:40 -0800
committerAlistair Francis <alistair.francis@wdc.com>2020-03-27 11:23:15 -0700
commitd1876749a8e51b3bd632561ed7dfcdbbfce59d33 (patch)
tree317cf974fd2e01c71e7dbe24d56530c39a8fb29e
parent4da2597af5cda0752c7526fe97398a5dafc15cbf (diff)
downloadglibc-d1876749a8e51b3bd632561ed7dfcdbbfce59d33.tar.gz
glibc-d1876749a8e51b3bd632561ed7dfcdbbfce59d33.tar.xz
glibc-d1876749a8e51b3bd632561ed7dfcdbbfce59d33.zip
time: Add a timeval with a 32-bit tv_sec and tv_usec
On y2038 safe 32-bit systems the Linux kernel expects itimerval to
use a 32-bit time_t, even though the other time_t's are 64-bit. To
address this let's add a __timeval32 struct to be used internally.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
-rw-r--r--include/time.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/time.h b/include/time.h
index 00b80eef00..96bd648c82 100644
--- a/include/time.h
+++ b/include/time.h
@@ -432,6 +432,51 @@ timespec64_to_timeval64 (const struct __timespec64 ts64)
   return tv64;
 }
 
+/* A version of 'struct timeval' with 32-bit time_t
+   and suseconds_t.  */
+struct __timeval32
+{
+  __int32_t tv_sec;         /* Seconds.  */
+  __int32_t tv_usec;        /* Microseconds.  */
+};
+
+/* Conversion functions for converting to/from __timeval32  */
+static inline struct __timeval64
+valid_timeval32_to_timeval64 (const struct __timeval32 tv)
+{
+  return (struct __timeval64) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct __timeval32
+valid_timeval64_to_timeval32 (const struct __timeval64 tv64)
+{
+  return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec };
+}
+
+static inline struct timeval
+valid_timeval32_to_timeval (const struct __timeval32 tv)
+{
+  return (struct timeval) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct __timeval32
+valid_timeval_to_timeval32 (const struct timeval tv)
+{
+  return (struct __timeval32) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct timespec
+valid_timeval32_to_timespec (const struct __timeval32 tv)
+{
+  return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
+}
+
+static inline struct __timeval32
+valid_timespec_to_timeval32 (const struct timespec ts)
+{
+  return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
+}
+
 /* Check if a value is in the valid nanoseconds range. Return true if
    it is, false otherwise.  */
 static inline bool