From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13671 invoked by alias); 25 Jul 2017 09:16:18 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 12797 invoked by uid 89); 25 Jul 2017 09:16:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2803 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 25 Jul 2017 09:16:16 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A20E13A45; Tue, 25 Jul 2017 09:16:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1A20E13A45 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=vinschen@redhat.com Received: from calimero.vinschen.de (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2175955C1; Tue, 25 Jul 2017 09:16:14 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id F25B7A804C4; Tue, 25 Jul 2017 11:16:13 +0200 (CEST) Date: Tue, 25 Jul 2017 09:16:00 -0000 From: Corinna Vinschen To: newlib@sourceware.org Cc: Brian.Inglis@SystematicSw.ab.ca Subject: Re: Cygwin strptime() is missing "%s" which strftime() has Message-ID: <20170725091613.GB14419@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org, Brian.Inglis@SystematicSw.ab.ca References: <851e9a02-f7c2-25c4-f37d-64d17d5c6d54@SystematicSw.ab.ca> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="UHN/qo2QbUvPLonB" Content-Disposition: inline In-Reply-To: <851e9a02-f7c2-25c4-f37d-64d17d5c6d54@SystematicSw.ab.ca> User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017/txt/msg00637.txt.bz2 --UHN/qo2QbUvPLonB Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2931 Hi Brian, On Jul 24 14:41, Brian Inglis wrote: > On Mon, 24 Jul 2017 02:32:14 -0700, Corinna Vinschen wrote:> On Jul 23 22= :07, > > In this case I have a nit, but this should be discussed on the right > > mailing list so all affected parties can chime in. Hint: strtoimax is > > not available on all platforms yet (patches still in limbo)... >=20 > Figured there would need to be some tweaks for newlib platforms, compiler= s, and > style, so made some changes, attached another diff for discussion, before > submitting a patch. > Let me know if you want conditionals or declarations changed, hoisted to > function start, case braces removed, other issues? See below. > diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c > index c0861eb87..112227e40 100644 > --- a/newlib/libc/time/strptime.c > +++ b/newlib/libc/time/strptime.c > @@ -38,6 +38,8 @@ > #include > #include > #include > +#include > +#include > #include "../locale/setlocale.h" >=20=20 > #define _ctloc(x) (_CurrentTimeLocale->x) > @@ -230,6 +232,13 @@ strptime_l (const char *buf, const char *format, str= uct tm *timeptr, > buf =3D s; > ymd |=3D SET_MDAY; > break; > + case 'F' : /* %Y-%m-%d */ > + s =3D strptime_l (buf, "%Y-%m-%d", timeptr, locale); > + if (s =3D=3D NULL) > + return NULL; > + buf =3D s; > + ymd |=3D SET_YMD; > + break; > case 'H' : > case 'k' : > ret =3D strtol_l (buf, &s, 10, locale); > @@ -300,6 +309,31 @@ strptime_l (const char *buf, const char *format, str= uct tm *timeptr, > return NULL; > buf =3D s; > break; > + case 's' : { > +#if defined(INTMAX_MAX) > +# define BIG_T intmax_t > +# define STRTOBIG strtoimax > +#elif defined(LLONG_MAX) > +# define BIG_T long long > +# define STRTOBIG strtoll > +#else > +# define BIG_T long > +# define STRTOBIG strtol > +#endif I don't think we need to use intmax_t at all here. Checking for LLONG_MAX should be sufficient. However, this is strptime_l. so you should use strtoll_l/strtol_l, just like the rest of the function. On second thought, do we have to do this at all? Our time_t is always long anyway so using just strtol_l and checking for ERANGE should be sufficient: int old_errno =3D _REENT->_errno; sec =3D strtol_l (buf, &s, 10); int new_errno =3D _REENT->_errno; _REENT->_errno =3D old_errno; if (s =3D=3D buf || new_errno =3D=3D ERANGE || etc... > + BIG_T sec; > + time_t t; > + > + sec =3D STRTOBIG (buf, &s, 10); > + t =3D (time_t)sec; > + if (s =3D=3D buf > + || (BIG_T)t !=3D sec > + || localtime_r (&t, timeptr) !=3D timeptr) Shouldn't this be gmtime_r? %s The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC). Leap seconds are not counted unless leap second support is available. Thanks, Corinna --=20 Corinna Vinschen Cygwin Maintainer Red Hat --UHN/qo2QbUvPLonB Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZdwxdAAoJEPU2Bp2uRE+gYBAP+wQptu5KYgr/ugJNzW2eGn2Z BOqm5G7Cm4F4HBEBdXYEk1WuxnIV78YjYtJ9fwIzRnI8xol+WyVqO3clO9MihORl hTiXb2Yb9FCZkAlqiB1aIGAtLVXJ6HqnfLkgweB3qFP5m4yCZOrImYL8JW2+FoY6 woFQ6Nm0JkdVqMNH6qSa02u2qCSB4H56wBipfXnerDjSAE5yHBeiblMgxWeAEMVW UjnkbwbKtmehYG+y34D6ViWohCJqZKVnRgjWI7OeTW/fQ74dvMpRrJ+PHNQWF9Da 5l/7qoUH87WrxHKe1hDhGxbC7rwdKahItzkBg8x8Y/Ej/q5nO3NVjYWUM4JbOA6i X9M4Rr9iHFOvQGrxqP3oyaHu/hbZbiKag6Ui1cGI8UqOgjfkFBDPKBhG2iNAhAQl LvhXZKoUedz3pWaQRfvxXNdBR/VsExZz5TEf7d843m9chAuMnGR//82HuhaB/dHg iT6GGuWjp6/u1f2VC1fBr5miXi7ir/z0P0GSfy8MCO3Bq7iqO0MtoxjQPYNOu3+A TH2nTokKnQ8P0R/50cYFQw6hMNQbTvQKTbzhoFLfLGF4kKiPROojDoXHhMMxKTAg BJpbJro2rs1RtO4lcrP4i8Y7R631KzuemwpKde/QJ5J6MOydnjEW6B5KAJUFPFZO Lbn1HDLFt/dSC+h6uDRX =vq0U -----END PGP SIGNATURE----- --UHN/qo2QbUvPLonB--