From patchwork Mon Jun 1 14:07:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 39403 X-Patchwork-Delegate: l.majewski@majess.pl 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 B9289388F062; Mon, 1 Jun 2020 14:08:19 +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 1CAAF388F046 for ; Mon, 1 Jun 2020 14:08:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1CAAF388F046 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 49bH802CQHz1rvSD; Mon, 1 Jun 2020 16:08:16 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 49bH8013xJz1qwwd; Mon, 1 Jun 2020 16:08:16 +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 ddSrv4C6wtN5; Mon, 1 Jun 2020 16:08:14 +0200 (CEST) X-Auth-Info: VtdJUd17iAxU9OgOVgwrV5n0lEEzTkCg8jSGU/mRKz8= 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; Mon, 1 Jun 2020 16:08:14 +0200 (CEST) From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Subject: [RFC 11/12] y2038: Convert timespec* files in ./support to be Y2038 safe Date: Mon, 1 Jun 2020 16:07:39 +0200 Message-Id: <20200601140740.16371-12-lukma@denx.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200601140740.16371-1-lukma@denx.de> References: <20200601140740.16371-1-lukma@denx.de> MIME-Version: 1.0 X-Spam-Status: No, score=-20.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, 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" After this change functions in ./support/timespec* files: - __timespec_add - __timespec_sub - test_timespec_before_impl - test_timespec_equal_or_after_impl are Y2038 safe, as the struct timespec and time_t have been replaced with struct __timespec64 and __time64_t respectively. --- support/timespec-add.c | 10 +++++----- support/timespec-sub.c | 16 ++++++++-------- support/timespec.c | 12 ++++++------ support/timespec.h | 17 +++++++++-------- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/support/timespec-add.c b/support/timespec-add.c index a2eb43791e..d2bcdae8de 100644 --- a/support/timespec-add.c +++ b/support/timespec-add.c @@ -25,11 +25,11 @@ #include "intprops.h" -struct timespec -__timespec_add (struct timespec a, struct timespec b) +struct __timespec64 +__timespec_add (struct __timespec64 a, struct __timespec64 b) { - time_t rs = a.tv_sec; - time_t bs = b.tv_sec; + __time64_t rs = a.tv_sec; + __time64_t bs = b.tv_sec; int ns = a.tv_nsec + b.tv_nsec; int nsd = ns - TIMESPEC_HZ; int rns = ns; @@ -37,7 +37,7 @@ __timespec_add (struct timespec a, struct timespec b) if (0 <= nsd) { rns = nsd; - time_t bs1; + __time64_t bs1; if (!INT_ADD_WRAPV (bs, 1, &bs1)) bs = bs1; else if (rs < 0) diff --git a/support/timespec-sub.c b/support/timespec-sub.c index 836f1e4f70..f0ae821ea4 100644 --- a/support/timespec-sub.c +++ b/support/timespec-sub.c @@ -26,21 +26,21 @@ #include "intprops.h" -struct timespec -__timespec_sub (struct timespec a, struct timespec b) +struct __timespec64 +__timespec_sub (struct __timespec64 a, struct __timespec64 b) { - time_t rs = a.tv_sec; - time_t bs = b.tv_sec; + __time64_t rs = a.tv_sec; + __time64_t bs = b.tv_sec; int ns = a.tv_nsec - b.tv_nsec; int rns = ns; if (ns < 0) { rns = ns + TIMESPEC_HZ; - time_t bs1; + __time64_t bs1; if (!INT_ADD_WRAPV (bs, 1, &bs1)) bs = bs1; - else if (- TYPE_SIGNED (time_t) < rs) + else if (- TYPE_SIGNED (__time64_t) < rs) rs--; else goto low_overflow; @@ -51,12 +51,12 @@ __timespec_sub (struct timespec a, struct timespec b) if (0 < bs) { low_overflow: - rs = TYPE_MINIMUM (time_t); + rs = TYPE_MINIMUM (__time64_t); rns = 0; } else { - rs = TYPE_MAXIMUM (time_t); + rs = TYPE_MAXIMUM (__time64_t); rns = TIMESPEC_HZ - 1; } } diff --git a/support/timespec.c b/support/timespec.c index 3647caed36..b69ce61c93 100644 --- a/support/timespec.c +++ b/support/timespec.c @@ -22,14 +22,14 @@ void test_timespec_before_impl (const char *file, int line, - const struct timespec left, - const struct timespec right) + const struct __timespec64 left, + const struct __timespec64 right) { if (left.tv_sec > right.tv_sec || (left.tv_sec == right.tv_sec && left.tv_nsec > right.tv_nsec)) { support_record_failure (); - const struct timespec diff = __timespec_sub (left, right); + const struct __timespec64 diff = __timespec_sub (left, right); printf ("%s:%d: %jd.%09jds not before %jd.%09jds " "(difference %jd.%09jds)\n", file, line, @@ -41,14 +41,14 @@ test_timespec_before_impl (const char *file, int line, void test_timespec_equal_or_after_impl (const char *file, int line, - const struct timespec left, - const struct timespec right) + const struct __timespec64 left, + const struct __timespec64 right) { if (left.tv_sec < right.tv_sec || (left.tv_sec == right.tv_sec && left.tv_nsec < right.tv_nsec)) { support_record_failure (); - const struct timespec diff = __timespec_sub (right, left); + const struct __timespec64 diff = __timespec_sub (right, left); printf ("%s:%d: %jd.%09jds not after %jd.%09jds " "(difference %jd.%09jds)\n", file, line, diff --git a/support/timespec.h b/support/timespec.h index 8de40d25f4..f0b054f5e9 100644 --- a/support/timespec.h +++ b/support/timespec.h @@ -23,10 +23,11 @@ #include #include #include +#include -struct timespec __timespec_add (struct timespec, struct timespec) +struct __timespec64 __timespec_add (struct __timespec64, struct __timespec64) __attribute__((const)); -struct timespec __timespec_sub (struct timespec, struct timespec) +struct __timespec64 __timespec_sub (struct __timespec64, struct __timespec64) __attribute__((const)); static inline struct __timespec64 @@ -41,12 +42,12 @@ __make_timespec (__time64_t s, long int ns) enum { TIMESPEC_HZ = 1000000000 }; void test_timespec_before_impl (const char *file, int line, - const struct timespec left, - const struct timespec right); + const struct __timespec64 left, + const struct __timespec64 right); void test_timespec_equal_or_after_impl (const char *file, int line, - const struct timespec left, - const struct timespec right); + const struct __timespec64 left, + const struct __timespec64 right); /* Check that the timespec on the left represents a time before the time on the right. */ @@ -55,7 +56,7 @@ void test_timespec_equal_or_after_impl (const char *file, int line, #define TEST_TIMESPEC_BEFORE_NOW(left, clockid) \ ({ \ - struct timespec now; \ + struct __timespec64 now; \ const int saved_errno = errno; \ __xclock_gettime ((clockid), &now); \ TEST_TIMESPEC_BEFORE ((left), now); \ @@ -69,7 +70,7 @@ void test_timespec_equal_or_after_impl (const char *file, int line, #define TEST_TIMESPEC_NOW_OR_AFTER(clockid, right) \ ({ \ - struct timespec now; \ + struct __timespec64 now; \ const int saved_errno = errno; \ __xclock_gettime ((clockid), &now); \ TEST_TIMESPEC_EQUAL_OR_AFTER (now, (right)); \