Hi,
> That one looks correct. OK millert@
Committed, thanks for checking!
While here, i noticed ugly preprocessor macros.
Let's make our future life easier by unifdefing a bit.
When compiling with -g0, there is no object change.
Note that if TM_ZONE is not defined, wcsftime.c doesn't
currently even compile. Talk about code in the tree that
is never tested.
OK?
Ingo
Index: localtime.c
===================================================================
RCS file: /cvs/src/lib/libc/time/localtime.c,v
retrieving revision 1.59
diff -u -p -r1.59 localtime.c
--- localtime.c 19 Sep 2016 12:48:21 -0000 1.59
+++ localtime.c 10 May 2019 22:17:14 -0000
@@ -46,7 +46,7 @@
** in which Daylight Saving Time is never observed.
** 4. They might reference tzname[0] after setting to a time zone
** in which Standard Time is never observed.
-** 5. They might reference tm.TM_ZONE after calling offtime.
+** 5. They might reference tm.tm_zone after calling offtime.
** What's best to do in the above cases is open to debate;
** for now, we just set things up so that in any of the five cases
** WILDABBR is used. Another possibility: initialize tzname[0] to the
@@ -214,14 +214,8 @@ DEF_WEAK(tzname);
static struct tm tm;
-#ifdef USG_COMPAT
long timezone = 0;
int daylight = 0;
-#endif /* defined USG_COMPAT */
-
-#ifdef ALTZONE
-time_t altzone = 0;
-#endif /* defined ALTZONE */
static long
detzcode(const char *codep)
@@ -255,13 +249,8 @@ settzname(void)
tzname[0] = wildabbr;
tzname[1] = wildabbr;
-#ifdef USG_COMPAT
daylight = 0;
timezone = 0;
-#endif /* defined USG_COMPAT */
-#ifdef ALTZONE
- altzone = 0;
-#endif /* defined ALTZONE */
if (sp == NULL) {
tzname[0] = tzname[1] = (char *)gmt;
return;
@@ -273,16 +262,10 @@ settzname(void)
const struct ttinfo *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 */
}
/*
** Finally, scrub the abbreviations.
@@ -1274,9 +1257,7 @@ localsub(const time_t *timep, long offse
result = timesub(&t, ttisp->tt_gmtoff, sp, tmp);
tmp->tm_isdst = ttisp->tt_isdst;
tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
-#ifdef TM_ZONE
- tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
-#endif /* defined TM_ZONE */
+ tmp->tm_zone = &sp->chars[ttisp->tt_abbrind];
return result;
}
@@ -1325,21 +1306,19 @@ gmtsub(const time_t *timep, long offset,
}
_THREAD_PRIVATE_MUTEX_UNLOCK(gmt);
result = timesub(timep, offset, gmtptr, tmp);
-#ifdef TM_ZONE
/*
** Could get fancy here and deliver something such as
** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,
** but this is no time for a treasure hunt.
*/
if (offset != 0)
- tmp->TM_ZONE = wildabbr;
+ tmp->tm_zone = wildabbr;
else {
if (gmtptr == NULL)
- tmp->TM_ZONE = (char *)gmt;
+ tmp->tm_zone = (char *)gmt;
else
- tmp->TM_ZONE = gmtptr->chars;
+ tmp->tm_zone = gmtptr->chars;
}
-#endif /* defined TM_ZONE */
return result;
}
@@ -1508,9 +1487,7 @@ timesub(const time_t *timep, long offset
idays -= ip[tmp->tm_mon];
tmp->tm_mday = (int) (idays + 1);
tmp->tm_isdst = 0;
-#ifdef TM_GMTOFF
- tmp->TM_GMTOFF = offset;
-#endif /* defined TM_GMTOFF */
+ tmp->tm_gmtoff = offset;
return tmp;
}
Index: private.h
===================================================================
RCS file: /cvs/src/lib/libc/time/private.h,v
retrieving revision 1.38
diff -u -p -r1.38 private.h
--- private.h 24 Oct 2015 18:13:18 -0000 1.38
+++ private.h 10 May 2019 22:17:14 -0000
@@ -9,12 +9,9 @@
*/
/* OpenBSD defaults */
-#define TM_GMTOFF tm_gmtoff
-#define TM_ZONE tm_zone
#define PCTS 1
#define ALL_STATE 1
#define STD_INSPIRED 1
-#define USG_COMPAT 1
/*
** This header is for use ONLY with the time conversion code.
Index: strftime.c
===================================================================
RCS file: /cvs/src/lib/libc/time/strftime.c,v
retrieving revision 1.30
diff -u -p -r1.30 strftime.c
--- strftime.c 21 Sep 2016 04:38:57 -0000 1.30
+++ strftime.c 10 May 2019 22:17:14 -0000
@@ -456,12 +456,9 @@ label:
pt, ptlim);
continue;
case 'Z':
-#ifdef TM_ZONE
- if (t->TM_ZONE != NULL)
- pt = _add(t->TM_ZONE, pt, ptlim);
- else
-#endif /* defined TM_ZONE */
- if (t->tm_isdst >= 0)
+ if (t->tm_zone != NULL)
+ pt = _add(t->tm_zone, pt, ptlim);
+ else if (t->tm_isdst >= 0)
pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
/*
@@ -477,41 +474,7 @@ label:
if (t->tm_isdst < 0)
continue;
-#ifdef TM_GMTOFF
- diff = t->TM_GMTOFF;
-#else /* !defined TM_GMTOFF */
- /*
- ** C99 says that the UTC offset must
- ** be computed by looking only at
- ** tm_isdst. This requirement is
- ** incorrect, since it means the code
- ** must rely on magic (in this case
- ** altzone and timezone), and the
- ** magic might not have the correct
- ** offset. Doing things correctly is
- ** tricky and requires disobeying C99;
- ** see GNU C strftime for details.
- ** For now, punt and conform to the
- ** standard, even though it's incorrect.
- **
- ** C99 says that %z must be replaced by the
- ** empty string if the time zone is not
- ** determinable, so output nothing if the
- ** appropriate variables are not available.
- */
- if (t->tm_isdst == 0)
-#ifdef USG_COMPAT
- diff = -timezone;
-#else /* !defined USG_COMPAT */
- continue;
-#endif /* !defined USG_COMPAT */
- else
-#ifdef ALTZONE
- diff = -altzone;
-#else /* !defined ALTZONE */
- continue;
-#endif /* !defined ALTZONE */
-#endif /* !defined TM_GMTOFF */
+ diff = t->tm_gmtoff;
if (diff < 0) {
sign = "-";
diff = -diff;
Index: strptime.c
===================================================================
RCS file: /cvs/src/lib/libc/time/strptime.c,v
retrieving revision 1.29
diff -u -p -r1.29 strptime.c
--- strptime.c 10 May 2019 21:39:05 -0000 1.29
+++ strptime.c 10 May 2019 22:17:14 -0000
@@ -416,21 +416,13 @@ literal:
tzset();
if (strncmp((const char *)bp, gmt, 3) == 0) {
tm->tm_isdst = 0;
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = 0;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = gmt;
-#endif
+ tm->tm_gmtoff = 0;
+ tm->tm_zone = gmt;
bp += 3;
} else if (strncmp((const char *)bp, utc, 3) == 0) {
tm->tm_isdst = 0;
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = 0;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = utc;
-#endif
+ tm->tm_gmtoff = 0;
+ tm->tm_zone = utc;
bp += 3;
} else {
ep = _find_string(bp, &i,
@@ -440,12 +432,8 @@ literal:
return (NULL);
tm->tm_isdst = i;
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = -(timezone);
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = tzname[i];
-#endif
+ tm->tm_gmtoff = -(timezone);
+ tm->tm_zone = tzname[i];
bp = ep;
}
continue;
@@ -479,12 +467,8 @@ literal:
/*FALLTHROUGH*/
case 'Z':
tm->tm_isdst = 0;
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = 0;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = utc;
-#endif
+ tm->tm_gmtoff = 0;
+ tm->tm_zone = utc;
continue;
case '+':
neg = 0;
@@ -496,24 +480,16 @@ literal:
--bp;
ep = _find_string(bp, &i, nast, NULL, 4);
if (ep != NULL) {
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = (-5 - i) * SECSPERHOUR;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = (char *)nast[i];
-#endif
+ tm->tm_gmtoff = (-5 - i) * SECSPERHOUR;
+ tm->tm_zone = (char *)nast[i];
bp = ep;
continue;
}
ep = _find_string(bp, &i, nadt, NULL, 4);
if (ep != NULL) {
tm->tm_isdst = 1;
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = (-4 - i) * SECSPERHOUR;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = (char *)nadt[i];
-#endif
+ tm->tm_gmtoff = (-4 - i) * SECSPERHOUR;
+ tm->tm_zone = (char *)nadt[i];
bp = ep;
continue;
}
@@ -534,12 +510,8 @@ literal:
if (neg)
offs = -offs;
tm->tm_isdst = 0; /* XXX */
-#ifdef TM_GMTOFF
- tm->TM_GMTOFF = offs;
-#endif
-#ifdef TM_ZONE
- tm->TM_ZONE = NULL; /* XXX */
-#endif
+ tm->tm_gmtoff = offs;
+ tm->tm_zone = NULL; /* XXX */
continue;
/*
Index: wcsftime.c
===================================================================
RCS file: /cvs/src/lib/libc/time/wcsftime.c,v
retrieving revision 1.6
diff -u -p -r1.6 wcsftime.c
--- wcsftime.c 9 Feb 2015 14:52:28 -0000 1.6
+++ wcsftime.c 10 May 2019 22:17:14 -0000
@@ -439,7 +439,7 @@ label:
continue;
case 'Z':
if (t->tm_zone != NULL)
- pt = _sadd(t->TM_ZONE, pt, ptlim);
+ pt = _sadd(t->tm_zone, pt, ptlim);
else
if (t->tm_isdst >= 0)
pt = _sadd(tzname[t->tm_isdst != 0],