[uClibc]sleep issue?

Manuel Novoa III mjn3 at codepoet.org
Fri May 16 19:25:13 UTC 2003


On Fri, May 16, 2003 at 10:57:41AM -0700, Steven Seeger wrote:
> Another thing I noticed is that if I make a timestruct tm with a month of
> April (3) and a day of 31, it doesn't turn it into May 1st when I use that
> to make a timeval and print it with asctime. Just an FYI.

Why would you expect asctime() to normalize the values of struct tm?
The only functime I'm aware of that does so (according to SUSv3) is
mktime().  See the following example, and note the comments about
the dst correction.

Manuel


#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    static struct tm stm;	/* static to 0-init via bss */

    stm.tm_mday = 31;
    stm.tm_mon = 3;
    stm.tm_year = 103;
    
    printf("asctime = %s", asctime(&stm));

    /* First, set TZ so we see the same behavior with both */
    /* glibc and uClibc.  Note that this will result in a */
    /* change to the hour as well, to correct for daylight */
    /* savings time.  You can avoid that by omitting the */
    /* dst specifier; say "TZ=CST6". */
    if (putenv("TZ=CST6CDT") == -1) {
    	printf("putenv failed!\n");
	return EXIT_FAILURE;
    }
    /* Ok.  Now normalize the struct vals and try again. */
    if (mktime(&stm) == -1) {
    	printf("mktime failed!\n");
	return EXIT_FAILURE;
    } 

    printf("asctime = %s", asctime(&stm));
    return EXIT_SUCCESS;
}



More information about the uClibc mailing list