This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC v6 03/23] time: Add a timeval with a long tv_sec and tv_usec
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: arnd at arndb dot de, adhemerval dot zanella at linaro dot org, fweimer at redhat dot com, joseph at codesourcery dot com, palmerdabbelt at google dot com, macro at wdc dot com, zongbox at gmail dot com, alistair dot francis at wdc dot com, alistair23 at gmail dot com
- Date: Sun, 12 Jan 2020 02:33:38 -0800
- Subject: [RFC v6 03/23] time: Add a timeval with a long tv_sec and tv_usec
- Ironport-sdr: EVSv4oM6xi8fbwCx36Mx9leuSkga/l72g8HKX9aGL6aH4YKTX5n8+TY76JOC249mNmTwz/dMb3 /xaGXmaD+O/fWpCmAN2uJcTce1bgcqng57qUVs9bH8NJjEjual7zaRqPC7zFLRxkBYDlkAQc9I Z20TzU921WbBm8gJvCUAwATC9Gu0m8cOhc+GFDCUm/a9u6A+qIhI5QWBSqQobM9oNHstAkcYoB 2p2UaJzAerOc8ZQescLuhr+rU1CdfRDdiKv0HuIMBM7m/RzxBP/1k6J5WExAcb43diAC8q5ozw E80=
- Ironport-sdr: JyROPqBuRibCdxjN2UDMx7PtIlxYdWfGyr/HFMLgWcCtYz6Q6tBX7KdrI4HswFU+TGiOgjiWMp c0bkHhTXMgAxMn6RP47vnB9kd6qkTLgcAQLdY8sX11HZn6MTRQCG1tbB/uBbCXIJxfZHWYP/Ix o9FlI2PLwno+bUXajTFjAqiepOt5c79UEjKF1pvY9pOWLxt5raveveFbF2hSHH+9ngquWtbLO3 oALKvGH5ozOYLRHAjVLsh9+lzKEU6Nq5v1S/WBpQVDyDtzerRYCW3B+E/GZIP7xIavaFYXZJiC +zlpmrpqulA5jP54Wq2WzqWr
- Ironport-sdr: //gRvITJop81LuLAshsyUjW6n1qumSuB1buEb6j8fpl9a8XIpj9rVg/oFQGRtTF0GCgKXkRFOI LsFKVuDPznLV+XU1s8U5CocW9XPTglnDaYrUZ1VivMYmovwA9hjPl/WvQIyK1lgw+kifVwpK1r dJBwT0gWmaelmRGWBeiKK7J702/tdH6azuNrgx6N5B0NoIT/oqvV8O1X4yOK6oH1x2gvsjUN/y eAygsiTLEPZSx1d82AvfzVVps5EjWldt6pYgMRjZhIsJiTgfxM122v/wXN8RAFIYyGy4Gmx9l9 qIg=
- References: <cover.1578824547.git.alistair.francis@wdc.com>
- Wdcironportexception: Internal
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 timeval_long struct to be used internally.
---
include/time.h | 29 +++++++++++++++++++++++++++++
time/bits/types/struct_timeval.h | 8 ++++++++
2 files changed, 37 insertions(+)
diff --git a/include/time.h b/include/time.h
index e5e8246eac..201342d1ca 100644
--- a/include/time.h
+++ b/include/time.h
@@ -310,6 +310,35 @@ valid_timespec64_to_timeval (const struct __timespec64 ts64)
return tv;
}
+/* Conversion functions for converting to/from __timeval_long
+. If the seconds field of a __timeval_long would
+ overflow, they write { INT32_MAX, 999999 } to the output. */
+static inline struct timeval
+valid_timeval_long_to_timeval64 (const struct __timeval_long tv)
+{
+ return (struct timeval) { tv.tv_sec, tv.tv_usec };
+}
+
+static inline struct __timeval_long
+valid_timeval64_to_timeval_long (const struct timeval tv64)
+{
+ if (__glibc_unlikely (tv64.tv_sec > (time_t) 2147483647))
+ return (struct __timeval_long) { 2147483647, 999999};
+ return (struct __timeval_long) { tv64.tv_sec, tv64.tv_usec };
+}
+
+static inline struct timespec
+valid_timeval_long_to_timespec (const struct __timeval_long tv)
+{
+ return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
+}
+
+static inline struct __timeval_long
+valid_timespec_to_timeval_long (const struct timespec ts)
+{
+ return (struct __timeval_long) { (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
diff --git a/time/bits/types/struct_timeval.h b/time/bits/types/struct_timeval.h
index 70394ce886..73697689cc 100644
--- a/time/bits/types/struct_timeval.h
+++ b/time/bits/types/struct_timeval.h
@@ -10,4 +10,12 @@ struct timeval
__time_t tv_sec; /* Seconds. */
__suseconds_t tv_usec; /* Microseconds. */
};
+
+/* A version of 'struct timeval' with `long` time_t
+ and suseconds_t. */
+struct __timeval_long
+{
+ long tv_sec; /* Seconds. */
+ long tv_usec; /* Microseconds. */
+};
#endif
--
2.24.1