From: Lukasz Majewski <lukma@denx.de>
To: Joseph Myers <joseph@codesourcery.com>,
Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Florian Weimer <fweimer@redhat.com>,
GNU C Library <libc-alpha@sourceware.org>,
Andreas Schwab <schwab@suse.de>,
Alistair Francis <alistair.francis@wdc.com>
Subject: [PATCH v2 5/7] y2038: Provide conversion helpers for struct __ntptimeval64
Date: Fri, 8 May 2020 16:56:38 +0200 [thread overview]
Message-ID: <20200508145640.16336-6-lukma@denx.de> (raw)
In-Reply-To: <20200508145640.16336-1-lukma@denx.de>
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
---
sysdeps/unix/sysv/linux/include/sys/timex.h | 36 +++++++++++++++++++++
1 file changed, 36 insertions(+)
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 */
--
2.20.1
next prev parent reply other threads:[~2020-05-08 14:57 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-08 14:56 [PATCH v2 0/7] y2038: Convert clock_adjtime related syscalls to support 64 bit time Lukasz Majewski
2020-05-08 14:56 ` [PATCH v2 1/7] y2038: linux: Provide __clock_adjtime64 implementation Lukasz Majewski
2020-05-15 10:03 ` Lukasz Majewski
2020-05-19 19:07 ` Adhemerval Zanella via Libc-alpha
2020-05-19 19:58 ` Lukasz Majewski
2020-05-08 14:56 ` [PATCH v2 2/7] y2038: linux: Provide ___adjtimex64 implementation Lukasz Majewski
2020-05-08 14:56 ` [PATCH v2 3/7] y2038: linux: Provide __adjtime64 implementation Lukasz Majewski
2020-05-08 14:56 ` [PATCH v2 4/7] y2038: Introduce struct __ntptimeval64 - new internal glibc type Lukasz Majewski
2020-05-19 19:10 ` Adhemerval Zanella via Libc-alpha
2020-05-08 14:56 ` Lukasz Majewski [this message]
2020-05-19 19:12 ` [PATCH v2 5/7] y2038: Provide conversion helpers for struct __ntptimeval64 Adhemerval Zanella via Libc-alpha
2020-05-08 14:56 ` [PATCH v2 6/7] y2038: linux: Provide __ntp_gettime64 implementation Lukasz Majewski
2020-05-19 19:18 ` Adhemerval Zanella via Libc-alpha
2020-05-19 20:20 ` Lukasz Majewski
2020-05-19 20:25 ` Adhemerval Zanella via Libc-alpha
2020-05-20 15:23 ` Joseph Myers
2020-05-20 17:08 ` Lukasz Majewski
2020-05-20 17:21 ` Joseph Myers
2020-05-21 10:31 ` Lukasz Majewski
2020-05-08 14:56 ` [PATCH v2 7/7] y2038: linux: Provide __ntp_gettimex64 implementation Lukasz Majewski
2020-05-19 19:19 ` Adhemerval Zanella via Libc-alpha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/libc/involved.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200508145640.16336-6-lukma@denx.de \
--to=lukma@denx.de \
--cc=adhemerval.zanella@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=fweimer@redhat.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
--cc=schwab@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).