From patchwork Mon Jun 7 20:36:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1488990 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=dVEYAoL0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FzQTz0GRzz9sRK for ; Tue, 8 Jun 2021 06:49:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 083C93938C02 for ; Mon, 7 Jun 2021 20:49:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 083C93938C02 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1623098981; bh=FDDNmb0/sQCffXC+DpT3zQx/mFPoYkXzwJOoojloz1k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dVEYAoL09FTTGzQKNbYqSVoRNBHF0i+hyQ1XlqpuEwRaaOxGARC/Qy0AOT8gowgSf Y8x/Wme2f2c8ZRvnTqStLGfO4H16KIDSIXR9VT0dd+Rx0sLMwdUAwPokPCpl4X2zdl THPM6SsXvQKhVrwa01Qm73asEue8/Ka0Fs7f53LA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by sourceware.org (Postfix) with ESMTPS id 35EB33938396 for ; Mon, 7 Jun 2021 20:36:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 35EB33938396 Received: by mail-qv1-xf2b.google.com with SMTP id e18so9600081qvm.10 for ; Mon, 07 Jun 2021 13:36:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FDDNmb0/sQCffXC+DpT3zQx/mFPoYkXzwJOoojloz1k=; b=rlULDNWNytRXwdAEXv1yuUcdnLnIXc5S/QnFGtuvTbHS2RLTb9K+EdzpBEfbOHTdKM iQsLiigdhrv7LfWZC5J87UgBycrAuNwGnzDPxDmXU39EknkJGjRc0H4jLUwvS4D0TrER 6WZULr+hvinHqEhgfL0Yrjpaos8Bkl6FaOAJsQWItkCZgW/1M43KyA657eGAQxysCio/ KMk8uqCRptNP1VCGnSYOJzxkHnpJ+ZIkLyjbiYYkuP6oau4QjuvDCHzCawv0unQoMHlb 1DCziFX5GVkityxAzS3EZIdgzCLmFfcWQrPhXiJZu+urRFkNgUO7UbaiPKKOH6K2GjgJ V93g== X-Gm-Message-State: AOAM531QgTiXR/MqNATBCyDPVqfrTeUHP6KnWYPY2si+g/LfHT44SyBO B67X5MCi2Jjaouva8r4mbZMJw8QCxuN7og== X-Google-Smtp-Source: ABdhPJyOH9UmBPQvu434KmFP7KmURvDFJ70l71i+L4XGxTQwCM0mRKfXaYPiWVVS4wYvhVgutK8T5Q== X-Received: by 2002:a0c:f80d:: with SMTP id r13mr10320453qvn.39.1623098206668; Mon, 07 Jun 2021 13:36:46 -0700 (PDT) Received: from birita.. ([177.194.59.218]) by smtp.googlemail.com with ESMTPSA id t196sm10422123qke.50.2021.06.07.13.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Jun 2021 13:36:46 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 17/24] time: Add 64-bit time support for getdate Date: Mon, 7 Jun 2021 17:36:06 -0300 Message-Id: <20210607203613.282543-18-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210607203613.282543-1-adhemerval.zanella@linaro.org> References: <20210607203613.282543-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" The getdate is basically a wrapper localtime and mktime. The 64-bit time support is done calling the 64-bit internal functions, there is no need to add a new symbol version. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Lukasz Majewski Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- include/sys/stat.h | 2 +- include/time.h | 12 ++++++++++-- time/getdate.c | 22 ++++++++++------------ time/tst-getdate.c | 14 ++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/include/sys/stat.h b/include/sys/stat.h index b4c9344628..13e777b3c7 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -46,7 +46,7 @@ hidden_proto (__lstat64) hidden_proto (__fstatat64) # endif -# if __TIMESIZE == 64 +# if __TIMESIZE == 64 || defined NO_RTLD_HIDDEN # define __stat64_time64 __stat64 # define __fstat64_time64 __fstat64 # define __lstat64_time64 __lstat64 diff --git a/include/time.h b/include/time.h index 4372bfbd96..980c6bd924 100644 --- a/include/time.h +++ b/include/time.h @@ -283,8 +283,8 @@ hidden_proto (__nanosleep64) #endif -extern int __getdate_r (const char *__string, struct tm *__resbufp) - attribute_hidden; +extern int __getdate_r (const char *__string, struct tm *__resbufp); +libc_hidden_proto (__getdate_r); /* Determine CLK_TCK value. */ @@ -509,6 +509,14 @@ time_now (void) return ts.tv_sec; } +static inline __time64_t +time64_now (void) +{ + struct __timespec64 ts; + __clock_gettime64 (TIME_CLOCK_GETTIME_CLOCKID, &ts); + return ts.tv_sec; +} + #define NSEC_PER_SEC 1000000000L /* Nanoseconds per second. */ #define USEC_PER_SEC 1000000L /* Microseconds per second. */ #define NSEC_PER_USEC 1000L /* Nanoseconds per microsecond. */ diff --git a/time/getdate.c b/time/getdate.c index 6e2f75566b..cdcc898517 100644 --- a/time/getdate.c +++ b/time/getdate.c @@ -112,16 +112,16 @@ __getdate_r (const char *string, struct tm *tp) size_t len; char *datemsk; char *result = NULL; - time_t timer; + __time64_t timer; struct tm tm; - struct stat64 st; - int mday_ok = 0; + struct __stat64_t64 st; + bool mday_ok = false; datemsk = getenv ("DATEMSK"); if (datemsk == NULL || *datemsk == '\0') return 1; - if (__stat64 (datemsk, &st) < 0) + if (__stat64_time64 (datemsk, &st) < 0) return 3; if (!S_ISREG (st.st_mode)) @@ -219,8 +219,8 @@ __getdate_r (const char *string, struct tm *tp) return 7; /* Get current time. */ - timer = time_now (); - __localtime_r (&timer, &tm); + timer = time64_now (); + __localtime64_r (&timer, &tm); /* If only the weekday is given, today is assumed if the given day is equal to the current day and next week if it is less. */ @@ -230,7 +230,7 @@ __getdate_r (const char *string, struct tm *tp) tp->tm_year = tm.tm_year; tp->tm_mon = tm.tm_mon; tp->tm_mday = tm.tm_mday + (tp->tm_wday - tm.tm_wday + 7) % 7; - mday_ok = 1; + mday_ok = true; } /* If only the month is given, the current month is assumed if the @@ -242,7 +242,7 @@ __getdate_r (const char *string, struct tm *tp) if (tp->tm_year == INT_MIN) tp->tm_year = tm.tm_year + (((tp->tm_mon - tm.tm_mon) < 0) ? 1 : 0); tp->tm_mday = first_wday (tp->tm_year, tp->tm_mon, tp->tm_wday); - mday_ok = 1; + mday_ok = true; } /* If no hour, minute and second are given the current hour, minute @@ -285,15 +285,13 @@ __getdate_r (const char *string, struct tm *tp) call normalizes the struct tm. */ if ((!mday_ok && !check_mday (TM_YEAR_BASE + tp->tm_year, tp->tm_mon, tp->tm_mday)) - || mktime (tp) == (time_t) -1) + || __mktime64 (tp) == (time_t) -1) return 8; return 0; } -#ifdef weak_alias weak_alias (__getdate_r, getdate_r) -#endif - +libc_hidden_def (__getdate_r) struct tm * getdate (const char *string) diff --git a/time/tst-getdate.c b/time/tst-getdate.c index c37ba3083a..3bb0e96707 100644 --- a/time/tst-getdate.c +++ b/time/tst-getdate.c @@ -115,20 +115,14 @@ do_test (void) { setenv ("TZ", tests[i].tz, 1); - int expected_err; - if (sizeof (time_t) == 4 && tests[i].time64) - expected_err = 8; - else - expected_err = 0; - tm = getdate (tests[i].str); - TEST_COMPARE (getdate_err, expected_err); - if (getdate_err != expected_err) + TEST_COMPARE (getdate_err, 0); + if (getdate_err != 0) { support_record_failure (); printf ("%s\n", report_date_error ()); } - else if (getdate_err == 0) + else { TEST_COMPARE (tests[i].tm.tm_mon, tm->tm_mon); TEST_COMPARE (tests[i].tm.tm_year, tm->tm_year); @@ -139,7 +133,7 @@ do_test (void) } struct tm tms; - TEST_COMPARE (getdate_r (tests[i].str, &tms), expected_err); + TEST_COMPARE (getdate_r (tests[i].str, &tms), 0); if (getdate_err == 0) { TEST_COMPARE (tests[i].tm.tm_mon, tms.tm_mon);