Cygwin strptime() is missing "%s" which strftime() has

Corinna Vinschen vinschen@redhat.com
Tue Jul 25 18:52:00 GMT 2017


On Jul 25 10:47, Brian Inglis wrote:
> On 2017-07-25 03:16, Corinna Vinschen wrote:
> > 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)...
> >>
> >> Figured there would need to be some tweaks for newlib platforms, compilers, 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?
> > [...]
> >> +	    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 = _REENT->_errno;
> >   sec = strtol_l (buf, &s, 10);
> >   int new_errno = _REENT->_errno;
> >   _REENT->_errno = old_errno;
> >   if (s == buf || new_errno == ERANGE || etc...
> > 
> >> +		    BIG_T sec;
> >> +		    time_t t;
> >> +
> >> +		    sec = STRTOBIG (buf, &s, 10);
> >> +		    t = (time_t)sec;
> >> +		    if (s == buf
> >> +			|| (BIG_T)t != sec
> >> +			|| localtime_r (&t, timeptr) != timeptr)
> 
> 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 <reent.h>"?

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?
> > 
> >  %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.
> 
> 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=UTC0, TZ=Etc/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

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20170725/2bf1862d/attachment.sig>


More information about the Newlib mailing list