[tz] small bug fix and ugliness concentration

Christos Zoulas christos at zoulas.com
Tue Nov 11 18:41:14 UTC 2014


Hello,

There there were 2 copies of the USG_COMPAT/ALTZONE ugliness and one
was incomplete (did not set daylight). I merged them.

christos

--- localtime.c.orig	2014-10-18 14:07:54.000000000 -0400
+++ localtime.c	2014-11-11 13:39:18.000000000 -0500
@@ -235,6 +235,27 @@
 	return result;
 }
 
+static char *
+setzone(struct state const *sp, const struct ttinfo *ttisp, int_fast32_t offset)
+{
+	char *zn = (char *)&sp->chars[ttisp->tt_abbrind];
+	if (offset) {
+#ifdef USG_COMPAT
+		if (ttisp->tt_isdst)
+			daylight = 1;
+		if (!ttisp->tt_isdst)
+			timezone = -(ttisp->tt_gmtoff);
+#endif /* defined USG_COMPAT */
+#ifdef ALTZONE
+		if (ttisp->tt_isdst)
+			altzone = -(ttisp->tt_gmtoff);
+#endif /* defined ALTZONE */
+	}
+
+	tzname[ttisp->tt_isdst] = zn;
+	return zn;
+}
+
 static void
 settzname(void)
 {
@@ -261,24 +282,8 @@
 
 		tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_abbrind];
 	}
-	for (i = 0; i < sp->timecnt; ++i) {
-		register const struct ttinfo * const	ttisp =
-							&sp->ttis[
-								sp->types[i]];
-
-		tzname[ttisp->tt_isdst] =
-			&sp->chars[ttisp->tt_abbrind];
-#ifdef USG_COMPAT
-		if (ttisp->tt_isdst)
-			daylight = 1;
-		if (!ttisp->tt_isdst)
-			timezone = -(ttisp->tt_gmtoff);
-#endif /* defined USG_COMPAT */
-#ifdef ALTZONE
-		if (ttisp->tt_isdst)
-			altzone = -(ttisp->tt_gmtoff);
-#endif /* defined ALTZONE */
-	}
+	for (i = 0; i < sp->timecnt; ++i)
+		setzone(sp, &sp->ttis[i], -1);
 	/*
 	** Finally, scrub the abbreviations.
 	** First, replace bogus characters.
@@ -1393,26 +1398,11 @@
 	*/
 	result = timesub(&t, ttisp->tt_gmtoff, sp, tmp);
 	if (result) {
-	  bool tm_isdst = ttisp->tt_isdst;
-	  char *tm_zone = (char *) &sp->chars[ttisp->tt_abbrind];
-	  result->tm_isdst = tm_isdst;
+		char *zn = setzone(sp, ttisp, offset);
+		result->tm_isdst = ttisp->tt_isdst;
 #ifdef TM_ZONE
-	  result->TM_ZONE = tm_zone;
+		result->TM_ZONE = zn;
 #endif /* defined TM_ZONE */
-	  if (offset) {
-	    /* Always set the tzname etc. vars whose values can easily
-	       be determined, as it's too much trouble to tell whether
-	       tzset has already done it correctly.  */
-	    tzname[tm_isdst] = tm_zone;
-#ifdef USG_COMPAT
-	    if (!tm_isdst)
-	      timezone = - ttisp->tt_gmtoff;
-#endif
-#ifdef ALTZONE
-	    if (tm_isdst)
-	      altzone = - ttisp->tt_gmtoff;
-#endif
-	  }
 	}
 	return result;
 }


More information about the tz mailing list