From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67883 invoked by alias); 25 Jul 2017 18:52:13 -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 67444 invoked by uid 89); 25 Jul 2017 18:52:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 18:52:08 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8AF23624D5 for ; Tue, 25 Jul 2017 18:52:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8AF23624D5 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 304BD5D96B for ; Tue, 25 Jul 2017 18:52:07 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 6F37BA80430; Tue, 25 Jul 2017 20:52:06 +0200 (CEST) Date: Tue, 25 Jul 2017 18:52:00 -0000 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: Cygwin strptime() is missing "%s" which strftime() has Message-ID: <20170725185206.GE14419@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <851e9a02-f7c2-25c4-f37d-64d17d5c6d54@SystematicSw.ab.ca> <20170725091613.GB14419@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rqzD5py0kzyFAOWN" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017/txt/msg00643.txt.bz2 --rqzD5py0kzyFAOWN Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 3763 On Jul 25 10:47, Brian Inglis wrote: > On 2017-07-25 03:16, Corinna Vinschen wrote: > > Hi Brian, > >=20 > > 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)... > >> > >> Figured there would need to be some tweaks for newlib platforms, compi= lers, and > >> style, so made some changes, attached another diff for discussion, bef= ore > >> submitting a patch. > >> Let me know if you want conditionals or declarations changed, hoisted = to > >> function start, case braces removed, other issues? > > [...] > >> + 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 > >=20 > > 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. > >=20 > > 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: > >=20 > > 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... > >=20 > >> + 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) >=20 > Is time_t always long on all newlib platforms, or could it be long > long in some environments/memory models e.g. Windows 64 VS/MinGW > LLP64/IL32P64 vs Cygwin/Unix LP64/I32LP64? Could/should we keep the > strtol[l] options and use the ..._l variants? Well... on *third* thought, targets may redefine time_t via redefining _TIME_T_. Targets not doing that will get long, so yeah, you're right. Maybe it is safer to use always strtoll_l and just break this down to time_t on the way. > Can't we just use errno, as shouldn't that be mapped to _REENT->_errno > in this context if required, or can it/does it need to be explicit? > These are locale-dependent ..._l functions not reentrant ..._r > functions, and there is no "#include "? No, I was just trying to be thorough. errno is fine, just include errno.h. > Don't we need to save and zero errno to distinguish a new error, and > restore if it stays zero, rather than just pick up the current value, > and assume if it is/was ERANGE it's bad? Right, I forget that when I typed the above. > > Shouldn't this be gmtime_r? > >=20 > > %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. >=20 > The input is seconds since the epoch, but the interpretation in struct > tm depends on the locale, so we use localtime_r(3). The timezone may > be set in the environment or locale, and may be UTC. If you want > gmtime/UTC you set TZ=3DUTC0, TZ=3DEtc/UTC, which should override/change > locale LC_TIME, as would setting %z with value +0000 or %Z with values > UTC or Z, where that is supported by strptime_l(3) (i.e. not here). Hmm, yes, ok, that makes sense. Thanks, Corinna --=20 Corinna Vinschen Cygwin Maintainer Red Hat --rqzD5py0kzyFAOWN Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZd5NWAAoJEPU2Bp2uRE+g4soP/jFFEU4YsP/iMgmw3fAmd+zV 4w66QCDADamyx7pNLZb1ZZJpXMEaEdgpx4IG59qix5u1f3FGIktndYL5IweDeNra WIfLpMWuY+km2s5VCs6T5SkWDZe874KY7ScWBtCyafSTjHVSAftf3ef7KlX7Ph3m mgDxo5eSTHwIjZE2bQVeiEah9xd617q/psUqc/pW0BV4mh+G+B8z7WzQLJJrgsg+ es5Cxp+yPHemhQYm1Hd9VYDcMGd0PVnnuxDYxc22+cBWp3busl2Cuco+c+BLncNt 8MZIUhIHgSt6KprX5oeEJceCT5ALCXIYJDfQ3dZDtdwm/GfFh9xiExgpiewMmGJy Eaq7ZjnuRk2PS/2D3LlGvtq5xBGw/Yq99gaB0ARg2IHGS9VKlXrteWx9i17v7m6O X1Zo4vJhuQlUrpeT0QU9bqHR/t4AbosP3uwq2i4rFka1q7kGWA9ynt7u+JoMDvFR tN+mKSbh2zeu0ScBnP3F4UjfBdBAccjcH6OPp9MsHrljbIrMRi/v5SfQ/35P64Qe CSG5sGcI+7ZPeT7eOcHLhiKVI+hyQXk38OhyTnSk5r+IZtBOgjPCb38fQTDBIAoA Kf7GNlZ6n+N6uWKXilKa1MNMLHrvR0vHRNbNSctUEIKXE3eaGOLGgsdutMlhSfeS U0hNGvZk422JU47NI2a1 =9xXJ -----END PGP SIGNATURE----- --rqzD5py0kzyFAOWN--