From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 68AC83858D38 for ; Thu, 26 Jan 2023 13:47:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68AC83858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x235.google.com with SMTP id v17so1409460oie.5 for ; Thu, 26 Jan 2023 05:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=g4EuhwKMAjNxA7SbmiV/I+u6sE1WgDGIyOplIaPjePI=; b=SjM4vVV7m28thmheuXeWiskwqvLPf+wqgV98IypC643jbxvr0NF6/bk5NUS4O+Ddmd SUedYZFXxQrcYuTuGdMTZNkO8S50uDShfFQE6XUC4h3pIbjxKLpwY8Qt8TTYXZb7rjh1 OhxKnvQzojBUKXwbPgugJLfz+OwQJcA9lKbWTfY3qaCOcPEH6K/XaD3tW6jpSMWhfrzT c5ezDXv0b+4D4hPJeIVM3/Ln790cIBL1oSGeoQEDHGfmedti+chT4yl4u6Q1qoHcbZRx a03jJNkVTABHlP/Uzac1aXw/E7th6s0+2QgdBinj+5PwyxwadwM+ERiBdok5Lp8tM7KF n+zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g4EuhwKMAjNxA7SbmiV/I+u6sE1WgDGIyOplIaPjePI=; b=EcqnoZZiZFe//WsQsgqhDCc0rOJnWPjR+jMMlyY+TnM/65DIKNNhrMF04b2lXrE897 EOg3la84GHCyS6wCXD8UfaeZkhO7gtT9FT4odPaRNOSozpc6FeqVx1EbdxXZgxQMnong LiZrxAmOS7mHRB4L8JTFLBwFP/z4sb1C8ea+N4PmYqHZsDhf2JlKTrFxYzmiI11fv4d7 gEBCfnuvwuh2jkPyR282cHqidDnKlcYgXmZY8+TJk8B9H1JHw4on49IrVu4dHpTZPHei 0SsUJlOlvBr7WkqQJrBSijg60UdQZhNGobZU49mRCy2PMP23b891Y6otssILoiNLOK4y MyzQ== X-Gm-Message-State: AFqh2kpPayYScg2rNf9jfHCy1utnARpSjCvHuv/10pQRKuzIjvA3cxC2 UOxoqv6+B3svegUzPqNcM99K1MpxDqMYPvACuD8= X-Google-Smtp-Source: AMrXdXtkoHc44+fa1KQvEavLe25ez3PjDXfAxoekte4/BshOnxcPLNMPrrtjjcOWEI2FPIhMf63mIg== X-Received: by 2002:a05:6808:3089:b0:363:4bfa:c904 with SMTP id bl9-20020a056808308900b003634bfac904mr20585334oib.19.1674740851927; Thu, 26 Jan 2023 05:47:31 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c1:7e99:6983:51e0:457e:734? ([2804:1b3:a7c1:7e99:6983:51e0:457e:734]) by smtp.gmail.com with ESMTPSA id r131-20020acada89000000b0035aa617156bsm424359oig.17.2023.01.26.05.47.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Jan 2023 05:47:31 -0800 (PST) Message-ID: <1d6daa89-fbec-461c-8423-eb785f89d4ab@linaro.org> Date: Thu, 26 Jan 2023 10:47:28 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.7.0 Subject: Re: [PATCH] Use 64-bit time_t interfaces in strftime and strptime (bug 30053) Content-Language: en-US To: Andreas Schwab , libc-alpha@sourceware.org References: From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 26/01/23 10:38, Andreas Schwab via Libc-alpha wrote: > Both functions use time_t only internally, so the ABI is not affected. > --- > time/Makefile | 3 ++- > time/strftime_l.c | 4 ++++ > time/strptime_l.c | 4 +++- > time/tst-y2038-time64.c | 1 + > time/tst-y2038.c | 52 +++++++++++++++++++++++++++++++++++++++++ > 5 files changed, 62 insertions(+), 2 deletions(-) > create mode 100644 time/tst-y2038-time64.c > create mode 100644 time/tst-y2038.c > > diff --git a/time/Makefile b/time/Makefile > index d86f2105c5..8b2e1d2398 100644 > --- a/time/Makefile > +++ b/time/Makefile > @@ -50,7 +50,7 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ > tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ > tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \ > tst-settimeofday tst-itimer tst-gmtime tst-timegm \ > - tst-timespec_get tst-timespec_getres > + tst-timespec_get tst-timespec_getres tst-y2038 > > tests-time64 := \ > tst-adjtime-time64 \ > @@ -68,6 +68,7 @@ tests-time64 := \ > tst-timegm-time64 \ > tst-timespec_get-time64 \ > tst-timespec_getres-time64 \ > + tst-y2038-time64 \ I think it should be renamed to tst-strftime4-time64 to show it is testing strftime. The rest of the patch looks ok. > tst-y2039-time64 > > include ../Rules > diff --git a/time/strftime_l.c b/time/strftime_l.c > index e09561c39c..402c6c4111 100644 > --- a/time/strftime_l.c > +++ b/time/strftime_l.c > @@ -159,6 +159,10 @@ extern char *tzname[]; > #ifdef _LIBC > # define tzname __tzname > # define tzset __tzset > + > +# define time_t __time64_t > +# define __gmtime_r(t, tp) __gmtime64_r (t, tp) > +# define mktime(tp) __mktime64 (tp) > #endif > > #if !HAVE_TM_GMTOFF > diff --git a/time/strptime_l.c b/time/strptime_l.c > index 80fd705b8d..85c3249fcc 100644 > --- a/time/strptime_l.c > +++ b/time/strptime_l.c > @@ -30,8 +30,10 @@ > #ifdef _LIBC > # define HAVE_LOCALTIME_R 0 > # include "../locale/localeinfo.h" > -#endif > > +# define time_t __time64_t > +# define __localtime_r(t, tp) __localtime64_r (t, tp) > +#endif > > #if ! HAVE_LOCALTIME_R && ! defined localtime_r > # ifdef _LIBC > diff --git a/time/tst-y2038-time64.c b/time/tst-y2038-time64.c > new file mode 100644 > index 0000000000..d6482b0be9 > --- /dev/null > +++ b/time/tst-y2038-time64.c > @@ -0,0 +1 @@ > +#include "tst-y2038.c" > diff --git a/time/tst-y2038.c b/time/tst-y2038.c > new file mode 100644 > index 0000000000..659716d0fa > --- /dev/null > +++ b/time/tst-y2038.c > @@ -0,0 +1,52 @@ > +/* Test strftime and strptime after 2038-01-19 03:14:07 UTC (bug 30053). > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > + > +static int > +do_test (void) > +{ > + TEST_VERIFY_EXIT (setenv ("TZ", "UTC0", 1) == 0); > + tzset (); > + if (sizeof (time_t) > 4) > + { > + time_t wrap = (time_t) 2147483648LL; > + char buf[80]; > + struct tm *tm = gmtime (&wrap); > + TEST_VERIFY_EXIT (tm != NULL); > + TEST_VERIFY_EXIT (strftime (buf, sizeof buf, "%s", tm) > 0); > + puts (buf); > + TEST_VERIFY (strcmp (buf, "2147483648") == 0); > + > + struct tm tm2; > + char *p = strptime (buf, "%s", &tm2); > + TEST_VERIFY_EXIT (p != NULL && *p == '\0'); > + time_t t = mktime (&tm2); > + printf ("%lld\n", (long long) t); > + TEST_VERIFY (t == wrap); > + } > + else > + FAIL_UNSUPPORTED ("32-bit time_t"); > + return 0; > +} > + > +#include