This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[glibc] y2038: Provide conversion helpers for struct __timespec64


https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9c44c6a908339e6d6eafa3639e641d5caea5e1ee

commit 9c44c6a908339e6d6eafa3639e641d5caea5e1ee
Author: Lukasz Majewski <lukma@denx.de>
Date:   Mon Mar 25 08:38:02 2019 +0100

    y2038: Provide conversion helpers for struct __timespec64
    
    Those functions allow easy conversion between Y2038 safe struct
    __timespec64 and other time related data structures (like struct timeval
    or struct timespec).
    
    * include/time.h (valid_timeval_to_timespec64): Add.
    * include/time.h (valid_timespec_to_timespec64): Likewise.
    * include/time.h (valid_timespec64_to_timespec): Likewise.
    * include/time.h (valid_timespec64_to_timeval): Likewise.

Diff:
---
 ChangeLog      |  7 +++++++
 include/time.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 17391d6..54288d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-10-01  Lukasz Majewski <lukma@denx.de>
+
+	* include/time.h (valid_timeval_to_timespec64): Add.
+	* include/time.h (valid_timespec_to_timespec64): Likewise.
+	* include/time.h (valid_timespec64_to_timespec): Likewise.
+	* include/time.h (valid_timespec64_to_timeval): Likewise.
+
 2019-09-30  Joseph Myers  <joseph@codesourcery.com>
 
 	* sysdeps/unix/sysv/linux/powerpc/bits/mman.h [__USE_MISC]
diff --git a/include/time.h b/include/time.h
index 9727786..9878c2b 100644
--- a/include/time.h
+++ b/include/time.h
@@ -178,5 +178,54 @@ in_time_t_range (__time64_t t)
   return s == t;
 }
 
+/* Convert a known valid struct timeval into a struct __timespec64.  */
+static inline struct __timespec64
+valid_timeval_to_timespec64 (const struct timeval tv)
+{
+  struct __timespec64 ts64;
+
+  ts64.tv_sec = tv.tv_sec;
+  ts64.tv_nsec = tv.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)
+{
+  struct __timespec64 ts64;
+
+  ts64.tv_sec = ts.tv_sec;
+  ts64.tv_nsec = ts.tv_nsec;
+
+  return ts64;
+}
+
+/* Convert a valid and within range of struct timespec, struct
+   __timespec64 into a struct timespec.  */
+static inline struct timespec
+valid_timespec64_to_timespec (const struct __timespec64 ts64)
+{
+  struct timespec ts;
+
+  ts.tv_sec = (time_t) ts64.tv_sec;
+  ts.tv_nsec = ts64.tv_nsec;
+
+  return ts;
+}
+
+/* Convert a valid and within range of struct timeval struct
+   __timespec64 into a struct timeval.  */
+static inline struct timeval
+valid_timespec64_to_timeval (const struct __timespec64 ts64)
+{
+  struct timeval tv;
+
+  tv.tv_sec = (time_t) ts64.tv_sec;
+  tv.tv_usec = ts64.tv_nsec / 1000;
+
+  return tv;
+}
 #endif
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]