[uClibc]strptime and mktime problem

Manuel Novoa III mjn3 at codepoet.org
Wed Jun 18 04:00:18 UTC 2003


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.

In my strptime() implementation, I chose to initialize all fields to
INT_MIN on entry in order to help detect non-portable usage.  I might
be persuaded to make that configurable.

>                              I tried to just 0 out the documented
> values before I called mktime, but in the 3rd line of the output
> it shows the tm struct is hosed by the mktime call.

Try setting the TZ env variable and see what happens.  There seems
to be some issue with PPC versions of gcc and the default uClibc
timezone initialization code.  This will throw off mktime().  See
   http://uclibc.org/lists/uclibc/2003-June/008653.html
for more information on that.  I tested with the latest uClibc
on x86, arm, and ppc.  Except for a daylight savings time issue
on PPC, I got the samve values on all platforms when setting TZ.

Since there seems to be a compiler issue for PPC and since that isn't
a platform I use, investigating this further isn't a high priority
for me.  But if you want to play with this some more , I'll gladly look
at whatever you come up with.

Manuel


More information about the uClibc mailing list