From a14127aa67c3af5870c62f40207f33b6c33c54b5 Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Sun, 22 Mar 2009 09:24:30 +0100 Subject: [PATCH] localtime(3) & zic(8): Clean up definitions a bit. --- lib/libc/stdtime/localtime.c | 118 +++-------------------------------- lib/libc/stdtime/private.h | 39 ------------ usr.sbin/zic/private.h | 31 --------- usr.sbin/zic/zdump/Makefile | 2 +- usr.sbin/zic/zic/Makefile | 2 +- 5 files changed, 12 insertions(+), 180 deletions(-) diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index 73af632626..bf94039a7b 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -45,18 +45,6 @@ #define TZ_ABBR_ERR_CHAR '_' #endif /* !defined TZ_ABBR_ERR_CHAR */ -/* -** SunOS 4.1.1 headers lack O_BINARY. -*/ - -#ifdef O_BINARY -#define OPEN_MODE (O_RDONLY | O_BINARY) -#endif /* defined O_BINARY */ -#ifndef O_BINARY -#define OPEN_MODE O_RDONLY -#endif /* !defined O_BINARY */ - -#ifndef WILDABBR /* ** Someone might make incorrect use of a time zone abbreviation: ** 1. They might reference tzname[0] before calling tzset (explicitly @@ -77,7 +65,6 @@ ** that tzname[0] has the "normal" length of three characters). */ #define WILDABBR " " -#endif /* !defined WILDABBR */ static char wildabbr[] = WILDABBR; @@ -194,17 +181,10 @@ static int tzload(const char * name, struct state * sp, static int tzparse(const char * name, struct state * sp, int lastditch); -#ifdef ALL_STATE -static struct state * lclptr; -static struct state * gmtptr; -#endif /* defined ALL_STATE */ - -#ifndef ALL_STATE static struct state lclmem; static struct state gmtmem; #define lclptr (&lclmem) #define gmtptr (&gmtmem) -#endif /* State Farm */ #ifndef TZ_STRLEN_MAX #define TZ_STRLEN_MAX 255 @@ -231,15 +211,6 @@ char * tzname[2] = { static struct tm tm; -#ifdef USG_COMPAT -time_t timezone = 0; -int daylight = 0; -#endif /* defined USG_COMPAT */ - -#ifdef ALTZONE -time_t altzone = 0; -#endif /* defined ALTZONE */ - static long detzcode(const char * const codep) { @@ -272,34 +243,12 @@ 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 */ -#ifdef ALL_STATE - if (sp == NULL) { - tzname[0] = tzname[1] = gmt; - return; - } -#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) { const struct ttinfo * const ttisp = &sp->ttis[i]; tzname[ttisp->tt_isdst] = &sp->chars[ttisp->tt_abbrind]; -#ifdef USG_COMPAT - if (ttisp->tt_isdst) - daylight = 1; - if (i == 0 || !ttisp->tt_isdst) - timezone = -(ttisp->tt_gmtoff); -#endif /* defined USG_COMPAT */ -#ifdef ALTZONE - if (i == 0 || ttisp->tt_isdst) - altzone = -(ttisp->tt_gmtoff); -#endif /* defined ALTZONE */ } /* ** And to get the latest zone names into tzname. . . @@ -395,7 +344,7 @@ tzload(const char *name, struct state * const sp, const int doextend) } if (doaccess && access(name, R_OK) != 0) return -1; - if ((fid = _open(name, OPEN_MODE)) == -1) + if ((fid = _open(name, O_RDONLY)) == -1) return -1; if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) { _close(fid); @@ -1149,15 +1098,6 @@ tzsetwall_basic(void) return; lcl_is_set = -1; -#ifdef ALL_STATE - if (lclptr == NULL) { - lclptr = (struct state *) malloc(sizeof *lclptr); - if (lclptr == NULL) { - settzname(); /* all we can do */ - return; - } - } -#endif /* defined ALL_STATE */ if (tzload((char *) NULL, lclptr, TRUE) != 0) gmtload(lclptr); settzname(); @@ -1188,15 +1128,6 @@ tzset_basic(void) if (lcl_is_set) strcpy(lcl_TZname, name); -#ifdef ALL_STATE - if (lclptr == NULL) { - lclptr = (struct state *) malloc(sizeof *lclptr); - if (lclptr == NULL) { - settzname(); /* all we can do */ - return; - } - } -#endif /* defined ALL_STATE */ if (*name == '\0') { /* ** User wants it fast rather than right. @@ -1243,10 +1174,7 @@ localsub(const time_t * const timep, const long offset __unused, const time_t t = *timep; sp = lclptr; -#ifdef ALL_STATE - if (sp == NULL) - return gmtsub(timep, offset, tmp); -#endif /* defined ALL_STATE */ + if ((sp->goback && t < sp->ats[0]) || (sp->goahead && t > sp->ats[sp->timecnt - 1])) { time_t newt = t; @@ -1379,11 +1307,7 @@ gmtsub(const time_t * const timep, const long offset, struct tm * const tmp) _MUTEX_LOCK(&gmt_mutex); if (!gmt_is_set) { gmt_is_set = TRUE; -#ifdef ALL_STATE - gmtptr = (struct state *) malloc(sizeof *gmtptr); - if (gmtptr != NULL) -#endif /* defined ALL_STATE */ - gmtload(gmtptr); + gmtload(gmtptr); } _MUTEX_UNLOCK(&gmt_mutex); result = timesub(timep, offset, gmtptr, tmp); @@ -1395,16 +1319,8 @@ gmtsub(const time_t * const timep, const long offset, struct tm * const tmp) */ if (offset != 0) tmp->TM_ZONE = wildabbr; - else { -#ifdef ALL_STATE - if (gmtptr == NULL) - tmp->TM_ZONE = gmt; - else tmp->TM_ZONE = gmtptr->chars; -#endif /* defined ALL_STATE */ -#ifndef ALL_STATE + else tmp->TM_ZONE = gmtptr->chars; -#endif /* State Farm */ - } #endif /* defined TM_ZONE */ return result; } @@ -1483,12 +1399,8 @@ timesub(const time_t * const timep, const long offset, corr = 0; hit = 0; -#ifdef ALL_STATE - i = (sp == NULL) ? 0 : sp->leapcnt; -#endif /* defined ALL_STATE */ -#ifndef ALL_STATE i = sp->leapcnt; -#endif /* State Farm */ + while (--i >= 0) { lp = &sp->lsis[i]; if (*timep >= lp->ls_trans) { @@ -1837,10 +1749,7 @@ time2sub(struct tm * const tmp, */ sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr); -#ifdef ALL_STATE - if (sp == NULL) - return WRONG; -#endif /* defined ALL_STATE */ + for (i = sp->typecnt - 1; i >= 0; --i) { if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) continue; @@ -1908,7 +1817,7 @@ time1(struct tm * const tmp, if (tmp->tm_isdst > 1) tmp->tm_isdst = 1; t = time2(tmp, funcp, offset, &okay); -#ifdef PCTS + /* ** PCTS code courtesy Grant Sullivan. */ @@ -1916,11 +1825,7 @@ time1(struct tm * const tmp, return t; if (tmp->tm_isdst < 0) tmp->tm_isdst = 0; /* reset to std and try again */ -#endif /* defined PCTS */ -#ifndef PCTS - if (okay || tmp->tm_isdst < 0) - return t; -#endif /* !defined PCTS */ + /* ** We're supposed to assume that somebody took a time of one type ** and did some math on it that yielded a "struct tm" that's bad. @@ -1928,10 +1833,7 @@ time1(struct tm * const tmp, ** type they need. */ sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr); -#ifdef ALL_STATE - if (sp == NULL) - return WRONG; -#endif /* defined ALL_STATE */ + for (i = 0; i < sp->typecnt; ++i) seen[i] = FALSE; nseen = 0; diff --git a/lib/libc/stdtime/private.h b/lib/libc/stdtime/private.h index 9618dba476..cc27ccd9c8 100644 --- a/lib/libc/stdtime/private.h +++ b/lib/libc/stdtime/private.h @@ -16,7 +16,6 @@ #ifndef TM_GMTOFF #define TM_GMTOFF tm_gmtoff #define TM_ZONE tm_zone -#define PCTS 1 #define TZDIR "/usr/share/zoneinfo" #endif /* ndef TM_GMTOFF */ @@ -44,41 +43,13 @@ #include /* for WIFEXITED and WEXITSTATUS */ -#ifndef WIFEXITED -#define WIFEXITED(status) (((status) & 0xff) == 0) -#endif /* !defined WIFEXITED */ -#ifndef WEXITSTATUS -#define WEXITSTATUS(status) (((status) >> 8) & 0xff) -#endif /* !defined WEXITSTATUS */ - #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */ -#ifndef F_OK -#define F_OK 0 -#endif /* !defined F_OK */ -#ifndef R_OK -#define R_OK 4 -#endif /* !defined R_OK */ - /* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ #define is_digit(c) ((unsigned)(c) - '0' <= 9) #include "stdint.h" -/* -** Workarounds for compilers/systems. -*/ - -/* -** Some time.h implementations don't declare asctime_r. -** Others might define it as a macro. -** Fix the former without affecting the latter. -*/ - -#ifndef asctime_r -extern char * asctime_r(struct tm const *, char *); -#endif - /* ** Private function declarations. */ @@ -171,25 +142,15 @@ const char * scheck(const char * string, const char * format); #define TZ_DOMAIN "tz" #endif /* !defined TZ_DOMAIN */ -#ifndef YEARSPERREPEAT #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ -#endif /* !defined YEARSPERREPEAT */ /* ** The Gregorian year averages 365.2425 days, which is 31556952 seconds. */ -#ifndef AVGSECSPERYEAR #define AVGSECSPERYEAR 31556952L -#endif /* !defined AVGSECSPERYEAR */ - -#ifndef SECSPERREPEAT #define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) -#endif /* !defined SECSPERREPEAT */ - -#ifndef SECSPERREPEAT_BITS #define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ -#endif /* !defined SECSPERREPEAT_BITS */ /* ** UNIX was a registered trademark of The Open Group in 2003. diff --git a/usr.sbin/zic/private.h b/usr.sbin/zic/private.h index 35858bf3ab..a33ea12cea 100644 --- a/usr.sbin/zic/private.h +++ b/usr.sbin/zic/private.h @@ -16,7 +16,6 @@ #ifndef TM_GMTOFF #define TM_GMTOFF tm_gmtoff #define TM_ZONE tm_zone -#define PCTS 1 #define TZDIR "/usr/share/zoneinfo" #endif /* ndef TM_GMTOFF */ @@ -44,41 +43,13 @@ #include /* for WIFEXITED and WEXITSTATUS */ -#ifndef WIFEXITED -#define WIFEXITED(status) (((status) & 0xff) == 0) -#endif /* !defined WIFEXITED */ -#ifndef WEXITSTATUS -#define WEXITSTATUS(status) (((status) >> 8) & 0xff) -#endif /* !defined WEXITSTATUS */ - #include "unistd.h" /* for F_OK, R_OK, and other POSIX goodness */ -#ifndef F_OK -#define F_OK 0 -#endif /* !defined F_OK */ -#ifndef R_OK -#define R_OK 4 -#endif /* !defined R_OK */ - /* Unlike 's isdigit, this also works if c < 0 | c > UCHAR_MAX. */ #define is_digit(c) ((unsigned)(c) - '0' <= 9) #include "stdint.h" -/* -** Workarounds for compilers/systems. -*/ - -/* -** Some time.h implementations don't declare asctime_r. -** Others might define it as a macro. -** Fix the former without affecting the latter. -*/ - -#ifndef asctime_r -extern char * asctime_r(struct tm const *, char *); -#endif - /* ** Private function declarations. */ @@ -171,9 +142,7 @@ const char * scheck(const char * string, const char * format); #define TZ_DOMAIN "tz" #endif /* !defined TZ_DOMAIN */ -#ifndef YEARSPERREPEAT #define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ -#endif /* !defined YEARSPERREPEAT */ /* ** UNIX was a registered trademark of The Open Group in 2003. diff --git a/usr.sbin/zic/zdump/Makefile b/usr.sbin/zic/zdump/Makefile index 9bc7f3df68..b602ddc068 100644 --- a/usr.sbin/zic/zdump/Makefile +++ b/usr.sbin/zic/zdump/Makefile @@ -8,7 +8,7 @@ PROG= zdump SRCS= zdump.c ialloc.c scheck.c MAN= ${.CURDIR}/../zdump.8 CFLAGS+= -I${.CURDIR}/.. -I${.CURDIR}/../../../lib/libc/stdtime -CFLAGS+= -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -DPCTS +CFLAGS+= -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone CFLAGS+= -DTZDIR=\"/usr/share/zoneinfo\" -Demkdir=mkdir .include diff --git a/usr.sbin/zic/zic/Makefile b/usr.sbin/zic/zic/Makefile index 0561f0363c..36a5bb98c6 100644 --- a/usr.sbin/zic/zic/Makefile +++ b/usr.sbin/zic/zic/Makefile @@ -8,7 +8,7 @@ PROG= zic SRCS= zic.c ialloc.c scheck.c MAN= ${.CURDIR}/../zic.8 CFLAGS+= -I${.CURDIR}/.. -I${.CURDIR}/../../../lib/libc/stdtime -CFLAGS+= -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone -DPCTS +CFLAGS+= -DTM_GMTOFF=tm_gmtoff -DTM_ZONE=tm_zone CFLAGS+= -DTZDIR=\"/usr/share/zoneinfo\" -Demkdir=mkdir .include -- 2.41.0