From patchwork Fri May 8 14:56:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 38939 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37E86397249F; Fri, 8 May 2020 14:57:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-out.m-online.net (mail-out.m-online.net [IPv6:2001:a60:0:28:0:1:25:1]) by sourceware.org (Postfix) with ESMTPS id 7A6B43972456 for ; Fri, 8 May 2020 14:57:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7A6B43972456 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 49JYMR52tKz1rt4G; Fri, 8 May 2020 16:57:07 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 49JYMR4p5Zz1r79j; Fri, 8 May 2020 16:57:07 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 3ue275_ctqA6; Fri, 8 May 2020 16:57:06 +0200 (CEST) X-Auth-Info: JuCLcvh9s/H4kTRm8gA9w2VQJU6cpVz7hOigQPOgoD4= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Fri, 8 May 2020 16:57:06 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Adhemerval Zanella Subject: [PATCH v2 5/7] y2038: Provide conversion helpers for struct __ntptimeval64 Date: Fri, 8 May 2020 16:56:38 +0200 Message-Id: <20200508145640.16336-6-lukma@denx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200508145640.16336-1-lukma@denx.de> References: <20200508145640.16336-1-lukma@denx.de> MIME-Version: 1.0 X-Spam-Status: No, score=-22.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Florian Weimer , GNU C Library , Andreas Schwab , Alistair Francis Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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 --- 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 */