Mail Archives: djgpp-workers/1996/10/18/08:43:04
===============================================================================
Markus F.X.J. Oberhumer <markus DOT oberhumer AT jk DOT uni-linz DOT ac DOT at>
Subject: mktime() bug ?
To: djgpp-workers AT delorie DOT com
===============================================================================
Some time ago I found a really annoying bug in mktime(). I encountered
it in stat() where it caused 'make' think that a file doesn't exist.
The bug prevented me to rebuild libc.a because out of the hundreds
of files in src/libc about 10 files had a timestamp that made mktime() fail.
Could someone please check if the following program works fine
with the latest snapshot ?
/***********************************************************************
// mktime fails on rare occasions
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(int argc, char *argv[])
{
struct tm tmm;
time_t t;
const char *tz;
/* the April 1995 bug can be reproduced with (at least) these timezones: */
putenv("TZ=MET-1MEST");
// putenv("TZ=e:/l/djgpp2/zoneinfo/met");
// putenv("TZ=e:/l/djgpp2/zoneinfo/gmt-1");
tzset();
memset(&tmm, 0, sizeof(struct tm));
tmm.tm_isdst = -1; /* let mktime() determine if DST is in effect */
tmm.tm_sec = 40;
tmm.tm_min = 22;
tmm.tm_hour = 2;
tmm.tm_mday = 2;
tmm.tm_year = 1995 - 1900;
/* 0 = January */
tmm.tm_mon = 5 - 1; /* May - this works with all timezones */
tmm.tm_mon = 4 - 1; /* April - !!! this fails !!! */
t = mktime(&tmm);
if (t == (time_t) -1)
printf("error !\n");
else
printf("%s",ctime(&t));
tz = getenv("TZ");
printf("TZ=%s\n", tz == NULL ? "" : tz);
return 0;
}
- Raw text -