Ok. I missed that you talked about the combination of SystemTimeToTzSpecificLocalTime and __loctotime_t.
Now I've investigated the origins of that code a bit more. It's actually originally from Microsofts own implementation of _stat in its C Runtime Library, which you get the source for with Visual Studio. It's then been hacked up a bit to fit pike (and the bug fixed, of course), but it's still a bit dubious if it's really kosher to have in pike.
This is what CRT does:
SYSTEMTIME SystemTime; FILETIME LocalFTime;
if ( !FileTimeToLocalFileTime( &findbuf.ftLastWriteTime, &LocalFTime ) || !FileTimeToSystemTime( &LocalFTime, &SystemTime ) ) { _dosmaperr( GetLastError() ); FindClose( findhandle ); return( -1 ); }
buf->st_mtime = __loctotime_t( SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, -1 );
In pike it's modified to:
SYSTEMTIME SystemTime; SYSTEMTIME UtcSTime;
if ( !FileTimeToSystemTime( &findbuf.ftLastWriteTime, &UtcSTime ) || !SystemTimeToTzSpecificLocalTime(NULL, &UtcSTime, &SystemTime) ) { _dosmaperr( GetLastError() ); FindClose( hFind ); return( -1 ); }
buf->st_mtime = __loctotime_t( SystemTime.wYear, SystemTime.wMonth, SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, -1 );
To me it pretty much looks like the person that did the pike fix didn't know a better way to convert a SYSTEMTIME to time_t. The bug that it corrects is in the use of FileTimeToLocalFileTime, which uses the current time and not the filestamp time to decide whether to add the DST hour or not.
Now why does CRT use the roundabout conversion it does? There's a comment a bit earlier:
* Note: We cannot directly use the file time stamps returned in the * WIN32_FIND_DATA structure. The values are supposedly in system time * and system time is ambiguously defined (it is UTC for Windows NT, local * time for Win32S and probably local time for Win32C). Therefore, these * values must be converted to local time before than can be used.
So I gather that older windowsen store local time in the timestamps, as opposed to NT, and that FileTimeToLocalFileTime is a nop on the old OS's. I wonder if the pike version works correctly on Win32S and Win32C systems (whichever Win9x they map to). Is the same OS specific conversion difference present in FileTimeToSystemTime?