diff options
author | Alistair Francis <alistair.francis@wdc.com> | 2019-12-27 09:07:40 -0800 |
---|---|---|
committer | Alistair Francis <alistair.francis@wdc.com> | 2020-01-14 21:11:13 -0800 |
commit | ae2c129da6496fe3783e26112cb330ce8ebbefae (patch) | |
tree | f1816c3d31ed4df021929b9f29bf8ea8f7191112 | |
parent | 0e0923421aa5def00ed507481fe6890cdd991175 (diff) | |
download | glibc-ae2c129da6496fe3783e26112cb330ce8ebbefae.tar.gz glibc-ae2c129da6496fe3783e26112cb330ce8ebbefae.tar.xz glibc-ae2c129da6496fe3783e26112cb330ce8ebbefae.zip |
time: Add a timeval with a long 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 timeval_long struct to be used internally.
-rw-r--r-- | include/time.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/include/time.h b/include/time.h index e5e8246eac..dbf6b7008a 100644 --- a/include/time.h +++ b/include/time.h @@ -310,6 +310,43 @@ valid_timespec64_to_timeval (const struct __timespec64 ts64) return tv; } +/* A version of 'struct timeval' with `long` time_t + and suseconds_t. */ +struct __timeval_long +{ + long tv_sec; /* Seconds. */ + long tv_usec; /* Microseconds. */ +}; + +/* 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 |