This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v5 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec
- From: Alistair Francis <alistair dot francis at wdc dot com>
- To: libc-alpha at sourceware dot org
- Cc: adhemerval dot zanella at linaro dot org, Alistair Francis <alistair dot francis at wdc dot com>, Lukasz Majewski <lukma at denx dot de>
- Date: Tue, 3 Mar 2020 09:53:49 -0800
- Subject: [PATCH v5 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec
- Ironport-sdr: w/kh1dCVc0++ww91etzFh0OMi/Bc9sgK74SVthVHgB6kS0i8BgVvVmWru6oC/ikXRVdKC3e4Qi 3yOuFBgyyQgTcT6lrvMVwnow3Vyq4bRYpZvKPQ3JuJU2tOe5rNaG8UMLidw+VhICvoGsX2tukN mUfIpeMEwcqLNA2dnyCLz41gV1fdg85h4y+0hMvo7LoH9vG9SuSx2AqFDBybYf90XNzrDzvsY2 LGTZQp/X4fNKT389Iq2lbqWZdmyDfZgnoPBIQugWLMtcozcnD7kZoYNgG5bFx5zkRDry4nzFD6 37E=
- Ironport-sdr: Fkr5mtDJmFuVnYTSMi6fQ83YA+YNBd1ZzN9cq53TX7pNUGky5i29s6hWoAClj2JsOg1XiA5FE8 q4e71L3WThm4dUXwyyUsH3w0hiKQISAu1a/u0/iGUL6UpoVtr87opSdMd92NFe/wKgWzoi3k0Y fVtc0sXPaMJrBhCQnKgouuK8aVCeubGhq2zXcYROiCzZXXCjzcQx3rjOoa63fjJXMToozx94pM Bi1IlO6QXhgCs6Ci5TmcI4QFRCh4JBj5aN6sirC9Me8xybMWD7XD5eD5P/Yk17l51d93Rs/mwP 1QL6zqB/T3Y0eQndna3v/Pcb
- Ironport-sdr: 050OwnO4HISpAhSRLJlP3WHYtKpzsAUq3eyoyEh+kJHM8xbytnDohL+RNvC+JSMI2vzyHdL221 eRKBi10BuIYDGsZqLxJMcIETsxF0eUTeCCkZJAz2doZXhnuWXQpAPdvzBkmuyg2XgW12RLlUL1 5xZaOWTyIACItxaUawVZ4wugPlShuk+yclHk++1ZGBTo85VzCgbHpUezUffQiMJxz4G3TB/N6n uyQ8Vnn6CGbjMDM/U1Fqaun9Fd5dbItG5Fh77OTYYs7UWxy+tT7AYKtC7e2wY8qPT+9RJWYO+R Cb8=
- References: <20200303175355.15770-1-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 __timeval32 struct to be used internally.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
---
include/time.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/include/time.h b/include/time.h
index 7737be1f7d..927b1ed587 100644
--- a/include/time.h
+++ b/include/time.h
@@ -422,6 +422,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
--
2.25.1