Challenge S server R4400 MIPS processor running IRIX 6.5.22m
Built from 8.6.6 source with MIPSPro compiler 7.4.4 with vendor-patches applied.
'make test' fails with:
==== clock-50.2 format / scan -2 as a local time FAILED
==== Contents of test case:
if {[catch {
clock scan [clock format -2 -format %Y%m%d%H%M%S -timezone :localtime]
-format %Y%m%d%H%M%S -timezone :localtime
} result]} {
if { [regexp " too large" $result] } {
set result -2
}
}
set result
---- Result was:
-1
---- Result should have been (exact matching):
-2
==== clock-50.2 FAILED
This happens only when time conversions are issued with '-timezone :localtime' option in the 'clock scan' command. Omitting this option or substituting it with '-timezone :Europe/Amsterdam' will produce the correct result. This is because the mktime() routine is called only when :localtime is issued, in tclClock.c:899 to be exact.
For completeness, in tcl this program shows the bug (expected -2, received -1):
set c [clock format -2 -format %Y%m%d%H%M%S -timezone :localtime]
puts [clock scan $c -format %Y%m%d%H%M%S -timezone :localtime]
produces:
cyane:~/tcltest> ../src/tcl8.6.6/unix/tcltest clock.tcl
-1
IRIX libc function mktime() is old and breaks for pre-1970 tm structs: It will return -1 for all values before the epoch.
On the other hand, localtime() accepts negative seconds and yields pre-epoch tm structs, so a conversion and back conversion yield different results for negative seconds. This test program demonstrates it:
#include <stdio.h>
#include <time.h>
int main ()
{
time_t endseconds, startseconds = -2;
endseconds = mktime( localtime( &startseconds ) );
printf("conversion of seconds %d via localtime and mktime is %d\n",startsecon
ds, endseconds);
return(0);
}
produces:
conversion of seconds -2 via localtime and mktime is -1
I have substituted the mktime() function in IRIX libc with a mktime.c implementation pulled from netBSD source archive and this fixes the result in the C-example program.
Adding a working mktime.c code in compat/ for IRIX builds with MIPSPro could work, or maybe re-route timezone calls with :localtime to a different function for IRIX.
|