public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
To: newlib@sourceware.org
Subject: Re: Cygwin strptime() is missing "%s" which strftime() has
Date: Tue, 25 Jul 2017 20:13:00 -0000	[thread overview]
Message-ID: <9c38bcee-fbb0-9a30-0c28-58629f54aa0e@SystematicSw.ab.ca> (raw)
In-Reply-To: <20170725185206.GE14419@calimero.vinschen.de>

On 2017-07-25 12:52, Corinna Vinschen wrote:
> On Jul 25 10:47, Brian Inglis wrote:
>> On 2017-07-25 03:16, Corinna Vinschen wrote:
>>> 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.

My concern has always been do all newlib RTEMS targets support long long, even
if same as long, and stroll_l?

>> 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.

K will change and check and format-patch.

Trying to build standalone or combined STC for this with changed strptime.c
ld/collect2 fails to resolve ...global_locale.
Of course STC alone builds and fails properly with current release.
Is there anything I can include or add somewhere to get this to build - recent
dev snapshot maybe?

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

  reply	other threads:[~2017-07-25 20:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <BY1PR09MB0343663DE41D927E67CF0CCEA5BB0@BY1PR09MB0343.namprd09.prod.outlook.com>
     [not found] ` <acc19ec5-055b-1bd4-997d-a247755163bf@SystematicSw.ab.ca>
2017-07-24 20:42   ` Brian Inglis
2017-07-24 21:36     ` Craig Howland
2017-07-24 23:04       ` Brian Inglis
2017-07-25  9:19       ` Corinna Vinschen
2017-07-25  9:16     ` Corinna Vinschen
2017-07-25 16:47       ` Brian Inglis
2017-07-25 17:38         ` Craig Howland
2017-07-25 18:52         ` Corinna Vinschen
2017-07-25 20:13           ` Brian Inglis [this message]
2017-07-26 10:49             ` Corinna Vinschen
2017-07-26 17:27               ` Brian Inglis
2017-07-26 19:34                 ` Corinna Vinschen
2017-07-28 20:50                   ` Brian Inglis
2017-07-31  9:55                     ` Corinna Vinschen
2017-08-18 18:53                       ` Corinna Vinschen
2017-08-18 19:38                         ` Brian Inglis
2017-08-18 19:38                       ` Brian Inglis
2017-08-18 20:01                       ` Brian Inglis
2017-08-19 14:01                       ` Brian Inglis
2017-08-21  3:09                         ` Brian Inglis
2017-08-21  9:10                           ` Corinna Vinschen
2017-08-24  2:14                             ` [PATCH] newlib/libc/time/strptime.c(strptime_l) add strptime %F %s Brian Inglis
2017-08-24  8:50                               ` Corinna Vinschen
2017-08-25  5:30                                 ` Brian Inglis
2017-08-25 12:06                                   ` Corinna Vinschen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9c38bcee-fbb0-9a30-0c28-58629f54aa0e@SystematicSw.ab.ca \
    --to=brian.inglis@systematicsw.ab.ca \
    --cc=newlib@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).