This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 5/6] y2038: Provide conversion helpers for struct __timeval64
- From: Lukasz Majewski <lukma at denx dot de>
- To: Joseph Myers <joseph at codesourcery dot com>, Paul Eggert <eggert at cs dot ucla dot edu>, Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, Samuel Thibault <samuel dot thibault at ens-lyon dot org>
- Cc: Alistair Francis <alistair23 at gmail dot com>, Alistair Francis <alistair dot francis at wdc dot com>, GNU C Library <libc-alpha at sourceware dot org>, Siddhesh Poyarekar <siddhesh at gotplt dot org>, Florian Weimer <fweimer at redhat dot com>, Florian Weimer <fw at deneb dot enyo dot de>, Zack Weinberg <zackw at panix dot com>, Carlos O'Donell <carlos at redhat dot com>, Andreas Schwab <schwab at suse dot de>, Lukasz Majewski <lukma at denx dot de>
- Date: Sat, 18 Jan 2020 08:20:46 +0100
- Subject: [PATCH 5/6] y2038: Provide conversion helpers for struct __timeval64
- References: <20200118072047.23071-1-lukma@denx.de>
Those functions allow easy conversion between Y2038 safe, glibc internal
struct __timeval64 and other time related data structures (like struct timeval
or struct __timespec64).
Build tests:
./src/scripts/build-many-glibcs.py glibcs
---
include/time.h | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/include/time.h b/include/time.h
index 22ecacd0d8..b40214c006 100644
--- a/include/time.h
+++ b/include/time.h
@@ -304,6 +304,30 @@ valid_timeval_to_timespec64 (const struct timeval tv)
return ts64;
}
+/* Convert a known valid struct timeval into a struct __timeval64. */
+static inline struct __timeval64
+valid_timeval_to_timeval64 (const struct timeval tv)
+{
+ struct __timeval64 tv64;
+
+ tv64.tv_sec = tv.tv_sec;
+ tv64.tv_usec = tv.tv_usec;
+
+ return tv64;
+}
+
+/* Convert a struct __timeval64 into a struct __timespec64. */
+static inline struct __timespec64
+timeval64_to_timespec64 (const struct __timeval64 tv64)
+{
+ struct __timespec64 ts64;
+
+ ts64.tv_sec = tv64.tv_sec;
+ ts64.tv_nsec = tv64.tv_usec * 1000;
+
+ return ts64;
+}
+
/* Convert a known valid struct timespec into a struct __timespec64. */
static inline struct __timespec64
valid_timespec_to_timespec64 (const struct timespec ts)
@@ -342,6 +366,18 @@ valid_timespec64_to_timeval (const struct __timespec64 ts64)
return tv;
}
+/* Convert a struct __timespec64 into a struct __timeval64. */
+static inline struct __timeval64
+timespec64_to_timeval64 (const struct __timespec64 ts64)
+{
+ struct __timeval64 tv64;
+
+ tv64.tv_sec = ts64.tv_sec;
+ tv64.tv_usec = ts64.tv_nsec / 1000;
+
+ return tv64;
+}
+
/* Check if a value is in the valid nanoseconds range. Return true if
it is, false otherwise. */
static inline bool
--
2.20.1