Problem
I am seeing incorrect behavior from the mktime(S) function. Every 64 days, mktime adjusts by 3 days worth of seconds, and then 1 day worth of seconds (86,400) every 64 days thereafter.
The following code can be used to display the problem:
#if 0
cc -o mktimetest mktimetest.c
exit 0
#endif/*
-- mktimetest.c -- This program tests the mktime math functions
*/
#include <stdio.h>
#include <time.h>/*
-- main --
*/
int main (int argc, char **argv)
{
struct tm tm;
time_t base_time;
time_t calc_time;
long gen_time;
long day_inc;/*
set so don't do daylight savings time stuff
*/
putenv ("TZ=pst8");/*
setup as 01/01/95 and form the long-timestamp
*/
memset (&tm, 0, sizeof (tm));
tm.tm_year = 95;
tm.tm_mon = 0;
tm.tm_mday = 1;
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = 0;
base_time = mktime (&tm);/*
loop for 364 days
*/
for (day_inc = 1; day_inc < 365; day_inc++) {
/*
** form expected date using "Seconds" math
**
** calc_time = base_time + (day_inc - 1) * 86400; <-works
** calc_time =(base_time + (day_inc - (long)1) * 86400); <- works
** calc_time =(long)(base_time + (day_inc - 1) * 86400); <-works
**
*/
calc_time = base_time + (day_inc - 1L) * 86400L;/*
** form the date using "days" math and mktime based on 01/01/95
*/
memset (&tm, 0, sizeof (tm));
gen_time = 0;
tm.tm_year = 95;
tm.tm_mon = 0;
tm.tm_mday = day_inc;
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = 0;
gen_time = mktime (&tm);/* calc_time and gen_time should be identical with no daylight savings time stuff */
printf ("day_inc: %3ld, calc: %ld, gen: %ld, diff: %ld\n",
day_inc, calc_time, gen_time, (calc_time - gen_time));
} /* for */} /* main */ Cause
The mktime(S) function call did not work in the original SVR5
code base. SCO acquired the patch for the function when the
source code tree was acquired from Novell. Solution
SCO Engineering reports that this problem will be addressed in a future release of the operating system.
A Technical Library Supplement (TLS) is available which contains the fixed object module for the mktime(S) function.
NOTE: Files offered as Technical Library Supplements are for
experimental or educational use only. They are provided
"AS IS" to knowledgeable users as a courtesy. All use of
TLS material is the sole responsibility of the user.Normally, the mktime(S) module resides in the standard C library: /usr/lib/libc.a.
There are several options in using this TLS. Perhaps the
simplest would be to add the mktime.o module to your
in-house code library. Then, include your library module
as the _last_ link module to the compiler directive. The
mktime(S) module will replace the one linked from the
standard C library.Officially, SCO Support does not support modifying the standard programming libraries.