about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukasz Majewski <lukma@denx.de>2020-04-23 00:20:51 +0200
committerLukasz Majewski <lukma@denx.de>2020-05-20 01:03:27 +0200
commit10ae49d2ce4576d8bb8f01d1fc1cbdf550ad4cbd (patch)
tree6b0fe2ed5198fe40f00e62bad2f3acd8e95d5e3f
parentdf4289508a3a0e345a87544ee4eea8cbb4c9d197 (diff)
downloadglibc-10ae49d2ce4576d8bb8f01d1fc1cbdf550ad4cbd.tar.gz
glibc-10ae49d2ce4576d8bb8f01d1fc1cbdf550ad4cbd.tar.xz
glibc-10ae49d2ce4576d8bb8f01d1fc1cbdf550ad4cbd.zip
y2038: Provide conversion helpers for struct __ntptimeval64
Those functions allow easy conversion between Y2038 safe, glibc internal
struct __ntptimeval64 and struct ntptimeval.

The reserved fields (i.e. __glibc_reserved{1234}) during conversion are
zeroed as well, to provide behavior similar to one in ntp_gettimex function
(where those are cleared before the struct ntptimeval is returned).

Those functions are put in Linux specific sys/timex.h file, as putting
them into glibc's local include/time.h would cause build break on HURD as
it doesn't support struct timex related syscalls.

Build tests:
./src/scripts/build-many-glibcs.py glibcs

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
-rw-r--r--sysdeps/unix/sysv/linux/include/sys/timex.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/include/sys/timex.h b/sysdeps/unix/sysv/linux/include/sys/timex.h
index 8c536b9a95..e762e03230 100644
--- a/sysdeps/unix/sysv/linux/include/sys/timex.h
+++ b/sysdeps/unix/sysv/linux/include/sys/timex.h
@@ -152,5 +152,41 @@ valid_timex64_to_timex (const struct __timex64 tx64)
 
   return tx;
 }
+
+/* Convert a known valid struct ntptimeval into a struct __ntptimeval64.  */
+static inline struct __ntptimeval64
+valid_ntptimeval_to_ntptimeval64 (const struct ntptimeval ntv)
+{
+  struct __ntptimeval64 ntv64;
+
+  ntv64.time = valid_timeval_to_timeval64 (ntv.time);
+  ntv64.maxerror = ntv.maxerror;
+  ntv64.esterror = ntv.esterror;
+  ntv64.tai = ntv.tai;
+  ntv64.__glibc_reserved1 = 0;
+  ntv64.__glibc_reserved2 = 0;
+  ntv64.__glibc_reserved3 = 0;
+  ntv64.__glibc_reserved4 = 0;
+
+  return ntv64;
+}
+
+/* Convert a known valid struct __ntptimeval64 into a struct ntptimeval.  */
+static inline struct ntptimeval
+valid_ntptimeval64_to_ntptimeval (const struct __ntptimeval64 ntp64)
+{
+  struct ntptimeval ntp;
+
+  ntp.time = valid_timeval64_to_timeval (ntp64.time);
+  ntp.maxerror = ntp64.maxerror;
+  ntp.esterror = ntp64.esterror;
+  ntp.tai = ntp64.tai;
+  ntp.__glibc_reserved1 = 0;
+  ntp.__glibc_reserved2 = 0;
+  ntp.__glibc_reserved3 = 0;
+  ntp.__glibc_reserved4 = 0;
+
+  return ntp;
+}
 # endif /* _ISOMAC */
 #endif /* sys/timex.h */