mktime and tm_isdst
Dan Nelson
dnelson at allantgroup.com
Thu Dec 4 18:31:56 PST 2003
In the last episode (Nov 21), Garrett Wollman said:
> <<On Fri, 21 Nov 2003 13:15:29 -0600, Dan Nelson <dnelson at allantgroup.com> said:
>
> > I've got a question about mktime and FreeBSD's use of the tm_isdst
> > flag.
>
> Suggest you compare with the original code at
> <ftp://elsie.nci.nih.gov/pub/> and bring up any unresolved issues on
> the tz at elsie.nci.nih.gov list. While the two codebases have evolved
> in somewhat different directions, the basic implementation should
> still be the same (and ours is probably wrong to the extent that it
> isn't).
It's an interaction with a bug in the original tzcode code and the
America/Chicago zone; it doesn't trigger for any other zone afaik. I'd
give an url for the patch, but there apparently is no web archive of
the list :( Patch attached instead; it's short.
--
Dan Nelson
dnelson at allantgroup.com
-------------- next part --------------
Index: localtime.c
===================================================================
RCS file: /home/ncvs/src/lib/libc/stdtime/localtime.c,v
retrieving revision 1.36
diff -u -r1.36 localtime.c
--- localtime.c 16 Feb 2003 17:29:11 -0000 1.36
+++ localtime.c 4 Dec 2003 04:17:11 -0000
@@ -1559,6 +1559,11 @@
time_t t;
const struct state * sp;
int samei, otheri;
+ int sameind, otherind;
+ int i;
+ int nseen;
+ int seen[TZ_MAX_TYPES];
+ int types[TZ_MAX_TYPES];
int okay;
if (tmp->tm_isdst > 1)
@@ -1592,10 +1597,20 @@
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
- for (samei = sp->typecnt - 1; samei >= 0; --samei) {
+ for (i = 0; i < sp->typecnt; ++i)
+ seen[i] = FALSE;
+ nseen = 0;
+ for (i = sp->timecnt - 1; i >= 0; --i)
+ if (!seen[sp->types[i]]) {
+ seen[sp->types[i]] = TRUE;
+ types[nseen++] = sp->types[i];
+ }
+ for (sameind = 0; sameind < nseen; ++sameind) {
+ samei = types[sameind];
if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
continue;
- for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
+ for (otherind = 0; otherind < nseen; ++otherind) {
+ otheri = types[otherind];
if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
continue;
tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -
More information about the freebsd-standards
mailing list