diff options
author | 2019-05-12 12:49:52 +0000 | |
---|---|---|
committer | 2019-05-12 12:49:52 +0000 | |
commit | bb5f5481f19635d142a1c2a56c775f73b38b4cef (patch) | |
tree | c863a170e35491c5919d9f6c53bd7edbb35f1447 /lib/libc/time | |
parent | document existing command status, and new command wipe (diff) | |
download | wireguard-openbsd-bb5f5481f19635d142a1c2a56c775f73b38b4cef.tar.xz wireguard-openbsd-bb5f5481f19635d142a1c2a56c775f73b38b4cef.zip |
Unifdef TM_GMTOFF TM_ZONE USG_COMPAT ALTZONE to make the code more readable.
No binary change when compiled with -g0.
Note that wcsftime.c did not even compile without TM_ZONE.
OK millert@
Diffstat (limited to 'lib/libc/time')
-rw-r--r-- | lib/libc/time/localtime.c | 37 | ||||
-rw-r--r-- | lib/libc/time/private.h | 5 | ||||
-rw-r--r-- | lib/libc/time/strftime.c | 47 | ||||
-rw-r--r-- | lib/libc/time/strptime.c | 58 | ||||
-rw-r--r-- | lib/libc/time/wcsftime.c | 4 |
5 files changed, 30 insertions, 121 deletions
diff --git a/lib/libc/time/localtime.c b/lib/libc/time/localtime.c index 2334b7465b7..fbe33e94aef 100644 --- a/lib/libc/time/localtime.c +++ b/lib/libc/time/localtime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: localtime.c,v 1.59 2016/09/19 12:48:21 millert Exp $ */ +/* $OpenBSD: localtime.c,v 1.60 2019/05/12 12:49:52 schwarze Exp $ */ /* ** This file is in the public domain, so clarified as of ** 1996-06-05 by Arthur David Olson. @@ -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 offset, struct tm *tmp) 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, struct tm *tmp) } _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, const struct state *sp, struct tm *tmp 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; } diff --git a/lib/libc/time/private.h b/lib/libc/time/private.h index f4f09e29851..a91502e50f2 100644 --- a/lib/libc/time/private.h +++ b/lib/libc/time/private.h @@ -1,4 +1,4 @@ -/* $OpenBSD: private.h,v 1.38 2015/10/24 18:13:18 guenther Exp $ */ +/* $OpenBSD: private.h,v 1.39 2019/05/12 12:49:52 schwarze Exp $ */ #ifndef PRIVATE_H #define PRIVATE_H @@ -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. diff --git a/lib/libc/time/strftime.c b/lib/libc/time/strftime.c index e45f7528e22..d618d2aa4e3 100644 --- a/lib/libc/time/strftime.c +++ b/lib/libc/time/strftime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strftime.c,v 1.30 2016/09/21 04:38:57 guenther Exp $ */ +/* $OpenBSD: strftime.c,v 1.31 2019/05/12 12:49:52 schwarze Exp $ */ /* ** Copyright (c) 1989, 1993 ** The Regents of the University of California. All rights reserved. @@ -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; diff --git a/lib/libc/time/strptime.c b/lib/libc/time/strptime.c index 05384d253e9..02017880457 100644 --- a/lib/libc/time/strptime.c +++ b/lib/libc/time/strptime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strptime.c,v 1.29 2019/05/10 21:39:05 schwarze Exp $ */ +/* $OpenBSD: strptime.c,v 1.30 2019/05/12 12:49:52 schwarze Exp $ */ /* $NetBSD: strptime.c,v 1.12 1998/01/20 21:39:40 mycroft Exp $ */ /*- * Copyright (c) 1997, 1998, 2005, 2008 The NetBSD Foundation, Inc. @@ -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; /* diff --git a/lib/libc/time/wcsftime.c b/lib/libc/time/wcsftime.c index 0678404012e..6870871bc74 100644 --- a/lib/libc/time/wcsftime.c +++ b/lib/libc/time/wcsftime.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wcsftime.c,v 1.6 2015/02/09 14:52:28 tedu Exp $ */ +/* $OpenBSD: wcsftime.c,v 1.7 2019/05/12 12:49:52 schwarze Exp $ */ /* ** Based on the UCB version with the ID appearing below. ** This is ANSIish only when "multibyte character == plain character". @@ -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], |