[uClibc]strptime and mktime problem
Andrew May
acmay at acmay.homeip.net
Wed Jun 18 05:50:44 UTC 2003
On Tue, Jun 17, 2003 at 10:00:18PM -0600, Manuel Novoa III wrote:
> Hello,
>
> On Tue, Jun 17, 2003 at 07:05:44PM -0700, Andrew May wrote:
> > I want to get the time_t for the first day of the month.
> >
> > For libc doing this is all that I seem to need.
> >
> > memset( &tm, 0, sizeof(tm) );
> > strptime("Jun-2003", "%b-%Y", &tm );
> > tm.tm_mday = 1;
> > stime = mktime(&tm);
> >
> > But with uclibc 0.9.19 on the PPC it does not seem to work.
> >
> > I have attached a program that shows the problem and I put the
> > output I saw in comment blocks.
> >
> > The first problem is that strptime() seems to screw up the values of
> > everthing in the tm struct.
>
> Well, as far as strptime() is concerned, your code above isn't portable.
> Quoting from the SUSv3 application usage notes regarding strptime():
>
> http://www.opengroup.org/onlinepubs/007904975/functions/strptime.html
>
> 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.
The note is regarding "multiple calls to strptime". Now the test code
does use the same struct in multiple calls, but I would argue that the
first call has values in the structure overwritten that I did not want
overwritten. So switch the lines strptime call and setting tm_mday to
make it clearer.
Like with just this code, since there is just one call to strptime I do
not think the above note applies and the results are not same as libc.
int main()
{
struct tm tm;
time_t stime;
memset(&tm, 0, sizeof(tm));
tm.tm_mday = 1;
strptime("Jun-2003", "%b-%Y", &tm );
printf("Mon %d Mday %d Year %d %02d:%02d.%02d YDay %d Wday %d\n",
tm.tm_mon, tm.tm_mday, tm.tm_year, tm.tm_hour, tm.tm_min,
tm.tm_sec, tm.tm_yday, tm.tm_wday);
return 0;
}
I have also been going by the man pages on my debian machines that have
this note.
=======================================================================
NOTES
In principle, this function does not initialize tm but only
stores the values specified. This means that tm should be
initialized before the call. Details differ a bit between
different Unix systems. The GNU libc implementation does not
touch those fields which are not explicitly specified, except
that it recomputes the tm_wday and tm_yday field if any of
the year, month, or day elements changed.
=======================================================================
I will have to get back to you on trying the TZ setting.
More information about the uClibc
mailing list