* strptime doesn't fill in tm_wday and tm_yday.
@ 2011-05-11 14:52 Peter Rosin
2011-05-11 17:35 ` Corinna Vinschen
0 siblings, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2011-05-11 14:52 UTC (permalink / raw)
To: cygwin
Hello!
The following STC hints at a problem in strptime:
-----------------------8<----------------------------
#include <stdio.h>
#include <time.h>
int
main(void)
{
/* seed tm with some garbage */
struct tm tm = {
0, 0, 0, /* s m h */
0, 0, 0, /* d m y */
290774, 2280577, 81
};
const char date[] = "2011-05-11 14:06:11";
if (!strptime(date, "%Y - %m - %d %T", &tm)) {
fprintf(stderr, "strptime error\n");
return 1;
}
printf("%s", asctime(&tm));
printf("tm_yday %d\n", tm.tm_yday);
printf("tm_wday %d\n", tm.tm_wday);
printf("tm_isdst %d\n", tm.tm_isdst);
return 0;
}
-----------------------8<----------------------------
I get this output with Cygwin 1.7.9-1:
May 11 14:06:11 2011
tm_yday 2280577
tm_wday 290774
tm_isdst 81
I expect:
Wed May 11 14:06:11 2011
tm_yday 130
tm_wday 3
tm_isdst whatever
I get the expected output on the Linux host I tried (with tm_isdst=81),
but not on Solaris 10.
On Solaris 10 I get (for completeness):
Sun May 11 14:06:11 2011
tm_yday 0
tm_wday 0
tm_isdst 0
Opengroup has this to say about only filling in some fields:
"It is unspecified whether multiple calls to strptime()
using the same tm structure will update the current
contents of the structure or overwrite all contents of
the structure. Conforming applications should make a
single call to strptime() with a format and all data
needed to completely specify the date and time being
converted."
but I don't think it applies since indeed I do completely specify
the date in my strptime call.
In my "real" program, the call to asctime with the crippled tm
causes a seg-fault instead of "just" missing weekday output, I guess
it depends...
Cheers,
Peter
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: strptime doesn't fill in tm_wday and tm_yday.
2011-05-11 14:52 strptime doesn't fill in tm_wday and tm_yday Peter Rosin
@ 2011-05-11 17:35 ` Corinna Vinschen
2011-05-12 9:01 ` Peter Rosin
0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2011-05-11 17:35 UTC (permalink / raw)
To: cygwin
On May 11 16:52, Peter Rosin wrote:
> Hello!
>
> The following STC hints at a problem in strptime:
>
> -----------------------8<----------------------------
> #include <stdio.h>
> #include <time.h>
>
> int
> main(void)
> {
> /* seed tm with some garbage */
> struct tm tm = {
> 0, 0, 0, /* s m h */
> 0, 0, 0, /* d m y */
> 290774, 2280577, 81
> };
> const char date[] = "2011-05-11 14:06:11";
>
> if (!strptime(date, "%Y - %m - %d %T", &tm)) {
> fprintf(stderr, "strptime error\n");
> return 1;
> }
>
> printf("%s", asctime(&tm));
> printf("tm_yday %d\n", tm.tm_yday);
> printf("tm_wday %d\n", tm.tm_wday);
> printf("tm_isdst %d\n", tm.tm_isdst);
> return 0;
> }
> -----------------------8<----------------------------
>
> I get this output with Cygwin 1.7.9-1:
> May 11 14:06:11 2011
> tm_yday 2280577
> tm_wday 290774
> tm_isdst 81
>
> I expect:
> Wed May 11 14:06:11 2011
> tm_yday 130
> tm_wday 3
> tm_isdst whatever
>
> I get the expected output on the Linux host I tried (with tm_isdst=81),
> but not on Solaris 10.
>
> On Solaris 10 I get (for completeness):
> Sun May 11 14:06:11 2011
> tm_yday 0
> tm_wday 0
> tm_isdst 0
>
> Opengroup has this to say about only filling in some fields:
>
> "It is unspecified whether multiple calls to strptime()
> using the same tm structure will update the current
> contents of the structure or overwrite all contents of
> the structure. Conforming applications should make a
> single call to strptime() with a format and all data
> needed to completely specify the date and time being
> converted."
>
> but I don't think it applies since indeed I do completely specify
> the date in my strptime call.
The Cygwin implementation of strptime is taken from NetBSD and enhanced
only in terms of support for the E and O modifiers. The NetBSD and
OpenBSD versions also support a non-POSIX format specifier %u (day of
week, monday = 1). Other than that, the Cygwin strptime behaves exactly
as the BSD implementation. tm_wday is only set if you specify %a, %A or
%w. tm_yday is only set if you specify %j.
Despite the example in the strptime man page of POSIX.1-2008, POSIX does
not specify that strptime has to fill out tm fields which are not also
specified in the format string. You should better memset the tm
structure to 0 before calling strptime.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: strptime doesn't fill in tm_wday and tm_yday.
2011-05-11 17:35 ` Corinna Vinschen
@ 2011-05-12 9:01 ` Peter Rosin
2011-05-12 11:12 ` Corinna Vinschen
0 siblings, 1 reply; 5+ messages in thread
From: Peter Rosin @ 2011-05-12 9:01 UTC (permalink / raw)
To: cygwin
Den 2011-05-11 19:34 skrev Corinna Vinschen:
> On May 11 16:52, Peter Rosin wrote:
>> Hello!
>>
>> The following STC hints at a problem in strptime:
...
>> Opengroup has this to say about only filling in some fields:
>>
>> "It is unspecified whether multiple calls to strptime()
>> using the same tm structure will update the current
>> contents of the structure or overwrite all contents of
>> the structure. Conforming applications should make a
>> single call to strptime() with a format and all data
>> needed to completely specify the date and time being
>> converted."
>>
>> but I don't think it applies since indeed I do completely specify
>> the date in my strptime call.
>
> The Cygwin implementation of strptime is taken from NetBSD and enhanced
> only in terms of support for the E and O modifiers. The NetBSD and
> OpenBSD versions also support a non-POSIX format specifier %u (day of
> week, monday = 1). Other than that, the Cygwin strptime behaves exactly
> as the BSD implementation. tm_wday is only set if you specify %a, %A or
> %w. tm_yday is only set if you specify %j.
>
> Despite the example in the strptime man page of POSIX.1-2008, POSIX does
> not specify that strptime has to fill out tm fields which are not also
> specified in the format string. You should better memset the tm
> structure to 0 before calling strptime.
Since you pulled out your "POSIX does not require it" card, I'm grasping
for my "Cygwin should behave like Linux" card. :-)
Seriously, of course I need to handle quirks in strptime if I want the
users of my application to be happy, but that does not mean that strptime
can't be a little bit more helpful on Cygwin. Maybe someone with a
copyright assignment can find some inspiration in the patch [1] I sent
for the newlib strptime?
Cheers,
Peter
[1] http://sourceware.org/ml/newlib/2011/msg00177.html
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: strptime doesn't fill in tm_wday and tm_yday.
2011-05-12 9:01 ` Peter Rosin
@ 2011-05-12 11:12 ` Corinna Vinschen
2011-05-12 11:18 ` Corinna Vinschen
0 siblings, 1 reply; 5+ messages in thread
From: Corinna Vinschen @ 2011-05-12 11:12 UTC (permalink / raw)
To: cygwin
On May 12 11:01, Peter Rosin wrote:
> Den 2011-05-11 19:34 skrev Corinna Vinschen:
> > On May 11 16:52, Peter Rosin wrote:
> >> Hello!
> >>
> >> The following STC hints at a problem in strptime:
> ...
> >> Opengroup has this to say about only filling in some fields:
> >>
> >> "It is unspecified whether multiple calls to strptime()
> >> using the same tm structure will update the current
> >> contents of the structure or overwrite all contents of
> >> the structure. Conforming applications should make a
> >> single call to strptime() with a format and all data
> >> needed to completely specify the date and time being
> >> converted."
> >>
> >> but I don't think it applies since indeed I do completely specify
> >> the date in my strptime call.
> >
> > The Cygwin implementation of strptime is taken from NetBSD and enhanced
> > only in terms of support for the E and O modifiers. The NetBSD and
> > OpenBSD versions also support a non-POSIX format specifier %u (day of
> > week, monday = 1). Other than that, the Cygwin strptime behaves exactly
> > as the BSD implementation. tm_wday is only set if you specify %a, %A or
> > %w. tm_yday is only set if you specify %j.
> >
> > Despite the example in the strptime man page of POSIX.1-2008, POSIX does
> > not specify that strptime has to fill out tm fields which are not also
> > specified in the format string. You should better memset the tm
> > structure to 0 before calling strptime.
>
> Since you pulled out your "POSIX does not require it" card, I'm grasping
> for my "Cygwin should behave like Linux" card. :-)
I'm not so much pulling the POSIX card, but rather the BSD/upstream
card. Consider this: The Cygwin version behaves pretty exactly like
the BSD version since it *is* the BSD version. Should you ever have
to port your application to Open/Free/NetBSD, you will see the exact
same problem. Whatever we do with the Cygwin strptime eventually,
you still have to consider that your application is *not* portable.
> Seriously, of course I need to handle quirks in strptime if I want the
> users of my application to be happy, but that does not mean that strptime
> can't be a little bit more helpful on Cygwin. Maybe someone with a
> copyright assignment can find some inspiration in the patch [1] I sent
> for the newlib strptime?
I'll take a look.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: strptime doesn't fill in tm_wday and tm_yday.
2011-05-12 11:12 ` Corinna Vinschen
@ 2011-05-12 11:18 ` Corinna Vinschen
0 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2011-05-12 11:18 UTC (permalink / raw)
To: cygwin
On May 12 13:11, Corinna Vinschen wrote:
> On May 12 11:01, Peter Rosin wrote:
> > Maybe someone with a copyright assignment [...]
Btw., that could be you! It's not that hard to send one. See the
"Before you get started" section on http://cygwin.com/contrib.html,.
Corinna
--
Corinna Vinschen Please, send mails regarding Cygwin to
Cygwin Project Co-Leader cygwin AT cygwin DOT com
Red Hat
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-05-12 11:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-11 14:52 strptime doesn't fill in tm_wday and tm_yday Peter Rosin
2011-05-11 17:35 ` Corinna Vinschen
2011-05-12 9:01 ` Peter Rosin
2011-05-12 11:12 ` Corinna Vinschen
2011-05-12 11:18 ` Corinna Vinschen
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).