* Makefile (typecheck): Add -D__time_t_defined to CFLAGS, for glibc 2.15. * asctime.c (asctime_r, asctime): * date.c (main, dogmt, reset, nondigit, sametm, convert, checkfinal): * ialloc.c (icatalloc): * localtime.c (detzcode, detzcode64, settzname, tzload) (typesequiv, getzname, getqzname, getnum, getsecs, getoffset) (getrule, transtime, tzparse, tzset, localsub, gmtsub) (leaps_thru_end_of, timesub, increment_overflow) (long_increment_overflow, normalize_overflow) (long_normalize_overflow, tmcomp, time2sub, time1, leapcorr): * scheck.c (scheck): * strftime.c (_yconv): * zdump.c (my_localtime, abbrok, main, yeartot, hunt) (delta, show, abbr, dumptime): * zic.c (main, dolink, itsdir, associate, infile, inrule) (inzone, inzcont, inzsub, inleap, inlink, rulesub, convert64) (writezone, doabbr, stringoffset, stringrule, stringzone) (outzone, addtype, leapadd, adjleap, ciequal, itsabbr, byword) (getfields, rpytime, newabbr, mkdirs): Omit 'register', as it adds no value these days. See Christos Zoulas in <http://mm.icann.org/pipermail/tz/2012-October/018376.html>. * date.c (netsettime) [TSP_SETDATE]: Add forward decl. Don't rely on implicit int. Now static. Use NULL, not 0. * zdump.c: Include "limits.h". (absolute_min_time, absolute_max_time): Compute at compile-time, as the run-time tests relied on undefined behavior. (checkabsolutes): Rename from setabsolutes. Just check, since there's nothing to set now. All uses changed. --- Makefile | 2 +- asctime.c | 8 +- date.c | 64 ++++++++------- ialloc.c | 4 +- localtime.c | 253 +++++++++++++++++++++++++++++----------------------------- scheck.c | 12 +-- strftime.c | 4 +- zdump.c | 162 ++++++++++++++++++------------------- zic.c | 254 +++++++++++++++++++++++++++++------------------------------ 9 files changed, 380 insertions(+), 383 deletions(-) diff --git a/Makefile b/Makefile index ffd1cf0..5477133 100644 --- a/Makefile +++ b/Makefile @@ -455,7 +455,7 @@ typecheck: make clean for i in "long long" unsigned double; \ do \ - make CFLAGS="-DTYPECHECK -D_TIME_T \"-Dtime_t=$$i\"" ; \ + make CFLAGS="-DTYPECHECK -D__time_t_defined -D_TIME_T \"-Dtime_t=$$i\"" ; \ ./zdump -v Europe/Rome ; \ make clean ; \ done diff --git a/asctime.c b/asctime.c index 152b0db..e81b4f0 100644 --- a/asctime.c +++ b/asctime.c @@ -69,7 +69,7 @@ static char buf_asctime[MAX_ASCTIME_BUF_SIZE]; */ char * -asctime_r(register const struct tm *timeptr, char *buf) +asctime_r(const struct tm *timeptr, char *buf) { static const char wday_name[][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" @@ -78,8 +78,8 @@ asctime_r(register const struct tm *timeptr, char *buf) "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - register const char * wn; - register const char * mn; + const char *wn; + const char *mn; char year[INT_STRLEN_MAXIMUM(int) + 2]; char result[MAX_ASCTIME_BUF_SIZE]; @@ -126,7 +126,7 @@ asctime_r(register const struct tm *timeptr, char *buf) */ char * -asctime(register const struct tm *timeptr) +asctime(const struct tm *timeptr) { return asctime_r(timeptr, buf_asctime); } diff --git a/date.c b/date.c index b9578e1..1839397 100644 --- a/date.c +++ b/date.c @@ -85,20 +85,20 @@ static void wildinput(const char *, const char *, int main(const int argc, char *argv[]) { - register const char * format; - register const char * value; - register const char * cp; - register int ch; - register int dousg; - register int aflag = 0; - register int dflag = 0; - register int nflag = 0; - register int tflag = 0; - register int minuteswest; - register int dsttime; - register double adjust; - time_t now; - time_t t; + const char * format; + const char * value; + const char * cp; + int ch; + int dousg; + int aflag = 0; + int dflag = 0; + int nflag = 0; + int tflag = 0; + int minuteswest; + int dsttime; + double adjust; + time_t now; + time_t t; INITIALIZE(dousg); INITIALIZE(minuteswest); @@ -305,9 +305,9 @@ dogmt(void) static char ** fakeenv; if (fakeenv == NULL) { - register int from; - register int to; - register int n; + int from; + int to; + int n; static char tzegmt0[] = "TZ=GMT0"; for (n = 0; environ[n] != NULL; ++n) @@ -343,7 +343,7 @@ dogmt(void) static void reset(const time_t newt, const int nflag) { - register int fid; + int fid; time_t oldt; static struct { struct utmp before; @@ -439,13 +439,17 @@ extern int logwtmp(); #define settimeofday(t, tz) (settimeofday)(t) #endif /* HAVE_SETTIMEOFDAY == 1 */ +#ifdef TSP_SETDATE +static int netsettime(struct timeval); +#endif + #ifndef TSP_SETDATE /*ARGSUSED*/ #endif /* !defined TSP_SETDATE */ static void reset(const time_t newt, const int nflag) { - register const char * username; + const char * username; static struct timeval tv; /* static so tv_usec is 0 */ #ifdef EBUG @@ -491,7 +495,7 @@ errensure(void) } static const char * -nondigit(register const char *cp) +nondigit(const char *cp) { while (is_digit(*cp)) ++cp; @@ -573,8 +577,7 @@ timeout(FILE *const fp, const char *const format, const struct tm *const tmp) } static int -sametm(register const struct tm *const atmp, - register const struct tm *const btmp) +sametm(const struct tm *const atmp, const struct tm *const btmp) { return atmp->tm_year == btmp->tm_year && atmp->tm_mon == btmp->tm_mon && @@ -592,11 +595,11 @@ sametm(register const struct tm *const atmp, #define ATOI2(ar) (ar[0] - '0') * 10 + (ar[1] - '0'); ar += 2; static time_t -convert(register const char * const value, const int dousg, const time_t t) +convert(const char * const value, const int dousg, const time_t t) { - register const char * cp; - register const char * dotp; - register int cent, year_in_cent, month, hour, day, mins, secs; + const char * cp; + const char * dotp; + int cent, year_in_cent, month, hour, day, mins, secs; struct tm tm, outtm; time_t outt; @@ -704,8 +707,8 @@ checkfinal(const char * const value, time_t othert; struct tm tm; struct tm othertm; - register int pass; - register long offset; + int pass; + long offset; /* ** See if there's both a USG and a BSD interpretation. @@ -800,6 +803,7 @@ iffy(const time_t thist, const time_t thatt, * notifies the master that a correction is needed. * Returns 1 on success, 0 on failure. */ +static int netsettime(struct timeval ntv) { int s, length, port, timed_ack, found, err; @@ -812,7 +816,7 @@ netsettime(struct timeval ntv) struct sockaddr_in sin, dest, from; sp = getservbyname("timed", "udp"); - if (sp == 0) { + if (! sp) { fputs(_("udp/timed: unknown service\n"), stderr); retval = 2; return (0); @@ -869,7 +873,7 @@ loop: tout.tv_usec = 0; FD_ZERO(&ready); FD_SET(s, &ready); - found = select(FD_SETSIZE, &ready, 0, 0, &tout); + found = select(FD_SETSIZE, &ready, NULL, NULL, &tout); length = sizeof err; if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char *)&err, &length) == 0 && err) { diff --git a/ialloc.c b/ialloc.c index b6f0188..6a565c6 100644 --- a/ialloc.c +++ b/ialloc.c @@ -10,8 +10,8 @@ char * icatalloc(char *const old, const char *const new) { - register char * result; - register int oldsize, newsize; + char * result; + int oldsize, newsize; newsize = (new == NULL) ? 0 : strlen(new); if (old == NULL) diff --git a/localtime.c b/localtime.c index e074c54..b045b93 100644 --- a/localtime.c +++ b/localtime.c @@ -226,8 +226,8 @@ time_t altzone = 0; static long detzcode(const char *const codep) { - register long result; - register int i; + long result; + int i; result = (codep[0] & 0x80) ? ~0L : 0; for (i = 0; i < 4; ++i) @@ -238,8 +238,8 @@ detzcode(const char *const codep) static time_t detzcode64(const char *const codep) { - register time_t result; - register int i; + time_t result; + int i; result = (codep[0] & 0x80) ? (~(int_fast64_t) 0) : 0; for (i = 0; i < 8; ++i) @@ -250,8 +250,8 @@ detzcode64(const char *const codep) static void settzname(void) { - register struct state * const sp = lclptr; - register int i; + struct state * const sp = lclptr; + int i; tzname[0] = wildabbr; tzname[1] = wildabbr; @@ -272,7 +272,7 @@ settzname(void) ** And to get the latest zone names into tzname. . . */ for (i = 0; i < sp->timecnt; ++i) { - register const struct ttinfo * const ttisp = + const struct ttinfo * const ttisp = &sp->ttis[ sp->types[i]]; @@ -300,8 +300,8 @@ settzname(void) ** Second, truncate long abbreviations. */ for (i = 0; i < sp->typecnt; ++i) { - register const struct ttinfo * const ttisp = &sp->ttis[i]; - register char * cp = &sp->chars[ttisp->tt_abbrind]; + const struct ttinfo * const ttisp = &sp->ttis[i]; + char * cp = &sp->chars[ttisp->tt_abbrind]; if (strlen(cp) > TZ_ABBR_MAX_LEN && strcmp(cp, GRANDPARENTED) != 0) @@ -319,14 +319,13 @@ differ_by_repeat(const time_t t1, const time_t t0) } static int -tzload(register const char *name, register struct state *const sp, - register const int doextend) +tzload(const char *name, struct state *const sp, const int doextend) { - register const char * p; - register int i; - register int fid; - register int stored; - register int nread; + const char * p; + int i; + int fid; + int stored; + int nread; typedef union { struct tzhead tzhead; char buf[2 * sizeof(struct tzhead) + @@ -334,21 +333,21 @@ tzload(register const char *name, register struct state *const sp, 4 * TZ_MAX_TIMES]; } u_t; #ifdef ALL_STATE - register u_t * up; + u_t * up; up = (u_t *) calloc(1, sizeof *up); if (up == NULL) return -1; #else /* !defined ALL_STATE */ - u_t u; - register u_t * const up = &u; + u_t u; + u_t * const up = &u; #endif /* !defined ALL_STATE */ sp->goback = sp->goahead = FALSE; if (name == NULL && (name = TZDEFAULT) == NULL) goto oops; { - register int doaccess; + int doaccess; /* ** Section 4.9.1 of the C standard says that ** "FILENAME_MAX expands to an integral constant expression @@ -422,7 +421,7 @@ tzload(register const char *name, register struct state *const sp, goto oops; } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; ttisp->tt_gmtoff = detzcode(p); @@ -439,7 +438,7 @@ tzload(register const char *name, register struct state *const sp, sp->chars[i] = *p++; sp->chars[i] = '\0'; /* ensure '\0' at end */ for (i = 0; i < sp->leapcnt; ++i) { - register struct lsinfo * lsisp; + struct lsinfo * lsisp; lsisp = &sp->lsis[i]; lsisp->ls_trans = (stored == 4) ? @@ -449,7 +448,7 @@ tzload(register const char *name, register struct state *const sp, p += 4; } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; if (ttisstdcnt == 0) @@ -462,7 +461,7 @@ tzload(register const char *name, register struct state *const sp, } } for (i = 0; i < sp->typecnt; ++i) { - register struct ttinfo * ttisp; + struct ttinfo * ttisp; ttisp = &sp->ttis[i]; if (ttisgmtcnt == 0) @@ -491,7 +490,7 @@ tzload(register const char *name, register struct state *const sp, /* ** Ignore the beginning (harder). */ - register int j; + int j; for (j = 0; j + i < sp->timecnt; ++j) { sp->ats[j] = sp->ats[j + i]; @@ -519,7 +518,7 @@ tzload(register const char *name, register struct state *const sp, up->buf[0] == '\n' && up->buf[nread - 1] == '\n' && sp->typecnt + 2 <= TZ_MAX_TYPES) { struct state ts; - register int result; + int result; up->buf[nread - 1] = '\0'; result = tzparse(&up->buf[1], &ts, FALSE); @@ -580,15 +579,15 @@ oops: static int typesequiv(const struct state *const sp, const int a, const int b) { - register int result; + int result; if (sp == NULL || a < 0 || a >= sp->typecnt || b < 0 || b >= sp->typecnt) result = FALSE; else { - register const struct ttinfo * ap = &sp->ttis[a]; - register const struct ttinfo * bp = &sp->ttis[b]; + const struct ttinfo * ap = &sp->ttis[a]; + const struct ttinfo * bp = &sp->ttis[b]; result = ap->tt_gmtoff == bp->tt_gmtoff && ap->tt_isdst == bp->tt_isdst && ap->tt_ttisstd == bp->tt_ttisstd && @@ -615,9 +614,9 @@ static const int year_lengths[2] = { */ static const char * -getzname(register const char *strp) +getzname(const char *strp) { - register char c; + char c; while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' && c != '+') @@ -635,9 +634,9 @@ getzname(register const char *strp) */ static const char * -getqzname(register const char *strp, const int delim) +getqzname(const char *strp, const int delim) { - register int c; + int c; while ((c = *strp) != '\0' && c != delim) ++strp; @@ -652,10 +651,10 @@ getqzname(register const char *strp, const int delim) */ static const char * -getnum(register const char *strp, int *const nump, const int min, const int max) +getnum(const char *strp, int *const nump, const int min, const int max) { - register char c; - register int num; + char c; + int num; if (strp == NULL || !is_digit(c = *strp)) return NULL; @@ -681,7 +680,7 @@ getnum(register const char *strp, int *const nump, const int min, const int max) */ static const char * -getsecs(register const char *strp, long *const secsp) +getsecs(const char *strp, long *const secsp) { int num; @@ -721,9 +720,9 @@ getsecs(register const char *strp, long *const secsp) */ static const char * -getoffset(register const char *strp, long *const offsetp) +getoffset(const char *strp, long *const offsetp) { - register int neg = 0; + int neg = 0; if (*strp == '-') { neg = 1; @@ -746,7 +745,7 @@ getoffset(register const char *strp, long *const offsetp) */ static const char * -getrule(const char *strp, register struct rule *const rulep) +getrule(const char *strp, struct rule *const rulep) { if (*strp == 'J') { /* @@ -799,12 +798,12 @@ getrule(const char *strp, register struct rule *const rulep) static time_t transtime(const time_t janfirst, const int year, - register const struct rule *const rulep, const long offset) + const struct rule *const rulep, const long offset) { - register int leapyear; - register time_t value; - register int i; - int d, m1, yy0, yy1, yy2, dow; + int leapyear; + time_t value; + int i; + int d, m1, yy0, yy1, yy2, dow; INITIALIZE(value); leapyear = isleap(year); @@ -890,20 +889,20 @@ transtime(const time_t janfirst, const int year, */ static int -tzparse(const char *name, register struct state *const sp, +tzparse(const char *name, struct state *const sp, const int lastditch) { - const char * stdname; - const char * dstname; - size_t stdlen; - size_t dstlen; - long stdoffset; - long dstoffset; - register time_t * atp; - register unsigned char * typep; - register char * cp; - register int load_result; - static struct ttinfo zttinfo; + const char * stdname; + const char * dstname; + size_t stdlen; + size_t dstlen; + long stdoffset; + long dstoffset; + time_t * atp; + unsigned char * typep; + char * cp; + int load_result; + static struct ttinfo zttinfo; INITIALIZE(dstname); stdname = name; @@ -958,8 +957,8 @@ tzparse(const char *name, register struct state *const sp, if (*name == ',' || *name == ';') { struct rule start; struct rule end; - register int year; - register time_t janfirst; + int year; + time_t janfirst; time_t starttime; time_t endtime; @@ -1016,12 +1015,12 @@ tzparse(const char *name, register struct state *const sp, janfirst = newfirst; } } else { - register long theirstdoffset; - register long theirdstoffset; - register long theiroffset; - register int isdst; - register int i; - register int j; + long theirstdoffset; + long theirdstoffset; + long theiroffset; + int isdst; + int i; + int j; if (*name != '\0') return -1; @@ -1163,7 +1162,7 @@ tzsetwall(void) void tzset(void) { - register const char * name; + const char * name; name = getenv("TZ"); if (name == NULL) { @@ -1216,11 +1215,11 @@ tzset(void) static struct tm * localsub(const time_t *const timep, const long offset, struct tm *const tmp) { - register struct state * sp; - register const struct ttinfo * ttisp; - register int i; - register struct tm * result; - const time_t t = *timep; + struct state * sp; + const struct ttinfo * ttisp; + int i; + struct tm * result; + const time_t t = *timep; sp = lclptr; #ifdef ALL_STATE @@ -1229,10 +1228,10 @@ localsub(const time_t *const timep, const long offset, struct tm *const tmp) #endif /* defined ALL_STATE */ if ((sp->goback && t < sp->ats[0]) || (sp->goahead && t > sp->ats[sp->timecnt - 1])) { - time_t newt = t; - register time_t seconds; - register time_t tcycles; - register int_fast64_t icycles; + time_t newt = t; + time_t seconds; + time_t tcycles; + int_fast64_t icycles; if (t < sp->ats[0]) seconds = sp->ats[0] - t; @@ -1254,7 +1253,7 @@ localsub(const time_t *const timep, const long offset, struct tm *const tmp) return NULL; /* "cannot happen" */ result = localsub(&newt, offset, tmp); if (result == tmp) { - register time_t newy; + time_t newy; newy = tmp->tm_year; if (t < sp->ats[0]) @@ -1274,11 +1273,11 @@ localsub(const time_t *const timep, const long offset, struct tm *const tmp) break; } } else { - register int lo = 1; - register int hi = sp->timecnt; + int lo = 1; + int hi = sp->timecnt; while (lo < hi) { - register int mid = (lo + hi) >> 1; + int mid = (lo + hi) >> 1; if (t < sp->ats[mid]) hi = mid; @@ -1326,7 +1325,7 @@ localtime_r(const time_t *const timep, struct tm *tmp) static struct tm * gmtsub(const time_t *const timep, const long offset, struct tm *const tmp) { - register struct tm * result; + struct tm * result; if (!gmt_is_set) { gmt_is_set = TRUE; @@ -1391,7 +1390,7 @@ offtime(const time_t *const timep, const long offset) */ static int -leaps_thru_end_of(register const int y) +leaps_thru_end_of(const int y) { return (y >= 0) ? (y / 4 - y / 100 + y / 400) : -(leaps_thru_end_of(-(y + 1)) + 1); @@ -1399,18 +1398,18 @@ leaps_thru_end_of(register const int y) static struct tm * timesub(const time_t *const timep, const long offset, - register const struct state *const sp, - register struct tm *const tmp) + const struct state *const sp, + struct tm *const tmp) { - register const struct lsinfo * lp; - register time_t tdays; - register int idays; /* unsigned would be so 2003 */ - register long rem; - int y; - register const int * ip; - register long corr; - register int hit; - register int i; + const struct lsinfo * lp; + time_t tdays; + int idays; /* unsigned would be so 2003 */ + long rem; + int y; + const int * ip; + long corr; + int hit; + int i; corr = 0; hit = 0; @@ -1444,10 +1443,10 @@ timesub(const time_t *const timep, const long offset, tdays = *timep / SECSPERDAY; rem = *timep - tdays * SECSPERDAY; while (tdays < 0 || tdays >= year_lengths[isleap(y)]) { - int newy; - register time_t tdelta; - register int idelta; - register int leapdays; + int newy; + time_t tdelta; + int idelta; + int leapdays; tdelta = tdays / DAYSPERLYEAR; idelta = tdelta; @@ -1465,7 +1464,7 @@ timesub(const time_t *const timep, const long offset, y = newy; } { - register long seconds; + long seconds; seconds = tdays * SECSPERDAY + 0.5; tdays = seconds / SECSPERDAY; @@ -1569,7 +1568,7 @@ ctime_r(const time_t *const timep, char *buf) static int increment_overflow(int *const ip, int j) { - register int const i = *ip; + int const i = *ip; /* ** If i >= 0 there can only be overflow if i + j > INT_MAX @@ -1586,7 +1585,7 @@ increment_overflow(int *const ip, int j) static int long_increment_overflow(long *const lp, int const m) { - register long const l = *lp; + long const l = *lp; if ((l >= 0) ? (m > LONG_MAX - l) : (m < LONG_MIN - l)) return TRUE; @@ -1597,7 +1596,7 @@ long_increment_overflow(long *const lp, int const m) static int normalize_overflow(int *const tensptr, int *const unitsptr, const int base) { - register int tensdelta; + int tensdelta; tensdelta = (*unitsptr >= 0) ? (*unitsptr / base) : @@ -1609,7 +1608,7 @@ normalize_overflow(int *const tensptr, int *const unitsptr, const int base) static int long_normalize_overflow(long *const tensptr, int *const unitsptr, const int base) { - register int tensdelta; + int tensdelta; tensdelta = (*unitsptr >= 0) ? (*unitsptr / base) : @@ -1619,10 +1618,10 @@ long_normalize_overflow(long *const tensptr, int *const unitsptr, const int base } static int -tmcomp(register const struct tm *const atmp, - register const struct tm *const btmp) +tmcomp(const struct tm *const atmp, + const struct tm *const btmp) { - register int result; + int result; if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && @@ -1640,17 +1639,17 @@ time2sub(struct tm *const tmp, int *const okayp, const int do_norm_secs) { - register const struct state * sp; - register int dir; - register int i, j; - register int saved_seconds; - register long li; - register time_t lo; - register time_t hi; - long y; - time_t newt; - time_t t; - struct tm yourtm, mytm; + const struct state * sp; + int dir; + int i, j; + int saved_seconds; + long li; + time_t lo; + time_t hi; + long y; + time_t newt; + time_t t; + struct tm yourtm, mytm; *okayp = FALSE; yourtm = *tmp; @@ -1838,15 +1837,15 @@ time1(struct tm *const tmp, struct tm *(*const funcp) (const time_t *, long, struct tm *), const long offset) { - register time_t t; - register const struct state * sp; - register int samei, otheri; - register int sameind, otherind; - register int i; - register int nseen; - int seen[TZ_MAX_TYPES]; - int types[TZ_MAX_TYPES]; - int okay; + 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 == NULL) { errno = EINVAL; @@ -1980,9 +1979,9 @@ gtime(struct tm *const tmp) static long leapcorr(time_t *timep) { - register struct state * sp; - register struct lsinfo * lp; - register int i; + struct state * sp; + struct lsinfo * lp; + int i; sp = lclptr; i = sp->leapcnt; diff --git a/scheck.c b/scheck.c index ed60980..95bb716 100644 --- a/scheck.c +++ b/scheck.c @@ -10,12 +10,12 @@ const char * scheck(const char *const string, const char *const format) { - register char * fbuf; - register const char * fp; - register char * tp; - register int c; - register const char * result; - char dummy; + char * fbuf; + const char * fp; + char * tp; + int c; + const char * result; + char dummy; result = ""; if (string == NULL || format == NULL) diff --git a/strftime.c b/strftime.c index 4950f74..5b302ac 100644 --- a/strftime.c +++ b/strftime.c @@ -587,8 +587,8 @@ static char * _yconv(const int a, const int b, const int convert_top, const int convert_yy, char *pt, const char *const ptlim) { - register int lead; - register int trail; + int lead; + int trail; #define DIVISOR 100 trail = a % DIVISOR + b % DIVISOR; diff --git a/zdump.c b/zdump.c index 6caa7a2..ddb46b9 100644 --- a/zdump.c +++ b/zdump.c @@ -17,6 +17,7 @@ #include "time.h" /* for struct tm */ #include "stdlib.h" /* for exit, malloc, atoi */ #include "float.h" /* for FLT_MAX and DBL_MAX */ +#include "limits.h" /* for CHAR_BIT, LLONG_MAX */ #include "ctype.h" /* for isalpha et al. */ #ifndef isascii #define isascii(x) 1 @@ -150,8 +151,35 @@ extern char * optarg; extern int optind; extern char * tzname[2]; -static time_t absolute_min_time; -static time_t absolute_max_time; +/* The minimum and maximum finite time values. Shift 'long long' or + 'long' instead of 'time_t'; this avoids compile-time errors when + time_t is floating-point. In practice, 'long long' is wide enough. */ +static time_t const absolute_min_time = + ((time_t) 0.5 == 0.5 + ? (sizeof (time_t) == sizeof (float) ? (time_t) -FLT_MAX + : sizeof (time_t) == sizeof (double) ? (time_t) -DBL_MAX + : sizeof (time_t) == sizeof (long double) ? (time_t) -LDBL_MAX + : 0) + : (time_t) -1 < 0 +#ifdef LLONG_MAX + ? (time_t) ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1)) +#else + ? (time_t) ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1)) +#endif + : 0); +static time_t const absolute_max_time = + ((time_t) 0.5 == 0.5 + ? (sizeof (time_t) == sizeof (float) ? (time_t) FLT_MAX + : sizeof (time_t) == sizeof (double) ? (time_t) DBL_MAX + : sizeof (time_t) == sizeof (long double) ? (time_t) LDBL_MAX + : -1) + : (time_t) -1 < 0 +#ifdef LLONG_MAX + ? (time_t) (- (~ 0 < 0) - ((long long) -1 << (CHAR_BIT * sizeof (time_t) - 1))) +#else + ? (time_t) (- (~ 0 < 0) - ((long) -1 << (CHAR_BIT * sizeof (time_t) - 1))) +#endif + : (time_t) -1); static size_t longest; static char * progname; static int warned; @@ -161,7 +189,7 @@ static void abbrok(const char * abbrp, const char * zone); static long delta(struct tm * newp, struct tm * oldp) ATTRIBUTE_PURE; static void dumptime(const struct tm * tmp); static time_t hunt(char * name, time_t lot, time_t hit); -static void setabsolutes(void); +static void checkabsolutes(void); static void show(char * zone, time_t t, int v); static const char * tformat(void); static time_t yeartot(long y) ATTRIBUTE_PURE; @@ -172,12 +200,12 @@ static time_t yeartot(long y) ATTRIBUTE_PURE; static struct tm * my_localtime(time_t *tp) { - register struct tm * tmp; + struct tm * tmp; tmp = localtime(tp); if (tp != NULL && tmp != NULL) { struct tm tm; - register time_t t; + time_t t; tm = *tmp; t = mktime(&tm); @@ -205,8 +233,8 @@ my_localtime(time_t *tp) static void abbrok(const char *const abbrp, const char *const zone) { - register const char * cp; - register const char * wp; + const char * cp; + const char * wp; if (warned) return; @@ -252,22 +280,22 @@ Report bugs to tz@elsie.nci.nih.gov.\n"), int main(int argc, char *argv[]) { - register int i; - register int c; - register int vflag; - register char * cutarg; - register long cutloyear = ZDUMP_LO_YEAR; - register long cuthiyear = ZDUMP_HI_YEAR; - register time_t cutlotime; - register time_t cuthitime; - register char ** fakeenv; - time_t now; - time_t t; - time_t newt; - struct tm tm; - struct tm newtm; - register struct tm * tmp; - register struct tm * newtmp; + int i; + int c; + int vflag; + char * cutarg; + long cutloyear = ZDUMP_LO_YEAR; + long cuthiyear = ZDUMP_HI_YEAR; + time_t cutlotime; + time_t cuthitime; + char ** fakeenv; + time_t now; + time_t t; + time_t newt; + struct tm tm; + struct tm newtm; + struct tm * tmp; + struct tm * newtmp; INITIALIZE(cutlotime); INITIALIZE(cuthitime); @@ -314,7 +342,7 @@ main(int argc, char *argv[]) exit(EXIT_FAILURE); } } - setabsolutes(); + checkabsolutes(); cutlotime = yeartot(cutloyear); cuthitime = yeartot(cuthiyear); } @@ -324,8 +352,8 @@ main(int argc, char *argv[]) if (strlen(argv[i]) > longest) longest = strlen(argv[i]); { - register int from; - register int to; + int from; + int to; for (i = 0; environ[i] != NULL; ++i) continue; @@ -404,56 +432,22 @@ main(int argc, char *argv[]) } static void -setabsolutes(void) +checkabsolutes(void) { - if (0.5 == (time_t) 0.5) { - /* - ** time_t is floating. - */ - if (sizeof (time_t) == sizeof (float)) { - absolute_min_time = (time_t) -FLT_MAX; - absolute_max_time = (time_t) FLT_MAX; - } else if (sizeof (time_t) == sizeof (double)) { - absolute_min_time = (time_t) -DBL_MAX; - absolute_max_time = (time_t) DBL_MAX; - } else { - (void) fprintf(stderr, + if (absolute_max_time < absolute_min_time) { + (void) fprintf(stderr, _("%s: use of -v on system with floating time_t other than float or double\n"), - progname); - exit(EXIT_FAILURE); - } - } else if (0 > (time_t) -1) { - /* - ** time_t is signed. Assume overflow wraps around. - */ - time_t t = 0; - time_t t1 = 1; - - while (t < t1) { - t = t1; - t1 = 2 * t1 + 1; - } - - absolute_max_time = t; - t = -t; - absolute_min_time = t - 1; - if (t < absolute_min_time) - absolute_min_time = t; - } else { - /* - ** time_t is unsigned. - */ - absolute_min_time = 0; - absolute_max_time = absolute_min_time - 1; + progname); + exit(EXIT_FAILURE); } } static time_t yeartot(const long y) { - register long myy; - register long seconds; - register time_t t; + long myy; + long seconds; + time_t t; myy = EPOCH_YEAR; t = 0; @@ -482,13 +476,13 @@ yeartot(const long y) static time_t hunt(char *name, time_t lot, time_t hit) { - time_t t; - long diff; - struct tm lotm; - register struct tm * lotmp; - struct tm tm; - register struct tm * tmp; - char loab[MAX_STRING_LENGTH]; + time_t t; + long diff; + struct tm lotm; + struct tm * lotmp; + struct tm tm; + struct tm * tmp; + char loab[MAX_STRING_LENGTH]; lotmp = my_localtime(&lot); if (lotmp != NULL) { @@ -529,8 +523,8 @@ hunt(char *name, time_t lot, time_t hit) static long delta(struct tm * newp, struct tm *oldp) { - register long result; - register int tmy; + long result; + int tmy; if (newp->tm_year < oldp->tm_year) return -delta(oldp, newp); @@ -550,7 +544,7 @@ delta(struct tm * newp, struct tm *oldp) static void show(char *zone, time_t t, int v) { - register struct tm * tmp; + struct tm * tmp; (void) printf("%-*s ", (int) longest, zone); if (v) { @@ -583,7 +577,7 @@ show(char *zone, time_t t, int v) static char * abbr(struct tm *tmp) { - register char * result; + char * result; static char nada; if (tmp->tm_isdst != 0 && tmp->tm_isdst != 1) @@ -620,7 +614,7 @@ tformat(void) } static void -dumptime(register const struct tm *timeptr) +dumptime(const struct tm *timeptr) { static const char wday_name[][3] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" @@ -629,10 +623,10 @@ dumptime(register const struct tm *timeptr) "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - register const char * wn; - register const char * mn; - register int lead; - register int trail; + const char * wn; + const char * mn; + int lead; + int trail; if (timeptr == NULL) { (void) printf("NULL"); diff --git a/zic.c b/zic.c index 64af1b2..28b2a24 100644 --- a/zic.c +++ b/zic.c @@ -440,9 +440,9 @@ static const char * yitcommand; int main(int argc, char **argv) { - register int i; - register int j; - register int c; + int i; + int j; + int c; #ifdef unix (void) umask(umask(S_IWGRP | S_IWOTH) | (S_IWGRP | S_IWOTH)); @@ -579,8 +579,8 @@ _("%s: More than one -L option specified\n"), static void dolink(const char *const fromfield, const char *const tofield) { - register char * fromname; - register char * toname; + char * fromname; + char * toname; if (fromfield[0] == '/') fromname = ecpyalloc(fromfield); @@ -614,7 +614,7 @@ dolink(const char *const fromfield, const char *const tofield) access(fromname, F_OK) == 0 && !itsdir(fromname)) { const char *s = tofield; - register char * symlinkcontents = NULL; + char *symlinkcontents = NULL; while ((s = strchr(s+1, '/')) != NULL) symlinkcontents = @@ -651,8 +651,8 @@ static const zic_t max_time = -1 - ((zic_t) -1 << (TIME_T_BITS_IN_FILE - 1)); static int itsdir(const char *const name) { - register char * myname; - register int accres; + char * myname; + int accres; myname = ecpyalloc(name); myname = ecatalloc(myname, "/."); @@ -679,10 +679,10 @@ rcomp(const void *cp1, const void *cp2) static void associate(void) { - register struct zone * zp; - register struct rule * rp; - register int base, out; - register int i, j; + struct zone * zp; + struct rule * rp; + int base, out; + int i, j; if (nrules != 0) { (void) qsort(rules, nrules, sizeof *rules, rcomp); @@ -754,14 +754,14 @@ associate(void) static void infile(const char *name) { - register FILE * fp; - register char ** fields; - register char * cp; - register const struct lookup * lp; - register int nfields; - register int wantcont; - register int num; - char buf[BUFSIZ]; + FILE * fp; + char ** fields; + char * cp; + const struct lookup * lp; + int nfields; + int wantcont; + int num; + char buf[BUFSIZ]; if (strcmp(name, "-") == 0) { name = _("standard input"); @@ -897,7 +897,7 @@ warning(_("values over 24 hours not handled by pre-2007 versions of zic")); } static void -inrule(register char **const fields, const int nfields) +inrule(char **const fields, const int nfields) { static struct rule r; @@ -923,9 +923,9 @@ inrule(register char **const fields, const int nfields) } static int -inzone(register char **const fields, const int nfields) +inzone(char **const fields, const int nfields) { - register int i; + int i; static char * buf; if (nfields < ZONE_MINFIELDS || nfields > ZONE_MAXFIELDS) { @@ -966,7 +966,7 @@ _("duplicate zone name %s (file \"%s\", line %d)"), } static int -inzcont(register char **const fields, const int nfields) +inzcont(char **const fields, const int nfields) { if (nfields < ZONEC_MINFIELDS || nfields > ZONEC_MAXFIELDS) { error(_("wrong number of fields on Zone continuation line")); @@ -976,14 +976,14 @@ inzcont(register char **const fields, const int nfields) } static int -inzsub(register char **const fields, const int nfields, const int iscont) +inzsub(char **const fields, const int nfields, const int iscont) { - register char * cp; + char * cp; static struct zone z; - register int i_gmtoff, i_rule, i_format; - register int i_untilyear, i_untilmonth; - register int i_untilday, i_untiltime; - register int hasuntil; + int i_gmtoff, i_rule, i_format; + int i_untilyear, i_untilmonth; + int i_untilday, i_untiltime; + int hasuntil; if (iscont) { i_gmtoff = ZFC_GMTOFF; @@ -1053,14 +1053,14 @@ inzsub(register char **const fields, const int nfields, const int iscont) } static void -inleap(register char ** const fields, const int nfields) +inleap(char ** const fields, const int nfields) { - register const char * cp; - register const struct lookup * lp; - register int i, j; - int year, month, day; - long dayoff, tod; - zic_t t; + const char * cp; + const struct lookup * lp; + int i, j; + int year, month, day; + long dayoff, tod; + zic_t t; if (nfields != LEAP_FIELDS) { error(_("wrong number of fields on Leap line")); @@ -1125,8 +1125,8 @@ inleap(register char ** const fields, const int nfields) tod = gethms(fields[LP_TIME], _("invalid time of day"), FALSE); cp = fields[LP_CORR]; { - register int positive; - int count; + int positive; + int count; if (strcmp(cp, "") == 0) { /* infile() turns "-" into "" */ positive = FALSE; @@ -1155,7 +1155,7 @@ inleap(register char ** const fields, const int nfields) } static void -inlink(register char **const fields, const int nfields) +inlink(char **const fields, const int nfields) { struct link l; @@ -1180,7 +1180,7 @@ inlink(register char **const fields, const int nfields) } static void -rulesub(register struct rule *const rp, +rulesub(struct rule *const rp, const char *const loyearp, const char *const hiyearp, const char *const typep, @@ -1188,10 +1188,10 @@ rulesub(register struct rule *const rp, const char *const dayp, const char *const timep) { - register const struct lookup * lp; - register const char * cp; - register char * dp; - register char * ep; + const struct lookup * lp; + const char * cp; + char * dp; + char * ep; if ((lp = byword(monthp, mon_names)) == NULL) { error(_("invalid month name")); @@ -1332,8 +1332,8 @@ rulesub(register struct rule *const rp, static void convert(const long val, char *const buf) { - register int i; - register int shift; + int i; + int shift; unsigned char *const b = (unsigned char *) buf; for (i = 0, shift = 24; i < 4; ++i, shift -= 8) @@ -1343,8 +1343,8 @@ convert(const long val, char *const buf) static void convert64(const zic_t val, char *const buf) { - register int i; - register int shift; + int i; + int shift; unsigned char *const b = (unsigned char *) buf; for (i = 0, shift = 56; i < 8; ++i, shift -= 8) @@ -1387,11 +1387,11 @@ is32(const zic_t x) static void writezone(const char *const name, const char *const string) { - register FILE * fp; - register int i, j; - register int leapcnt32, leapi32; - register int timecnt32, timei32; - register int pass; + FILE * fp; + int i, j; + int leapcnt32, leapi32; + int timecnt32, timei32; + int pass; static char * fullname; static const struct tzhead tzh0; static struct tzhead tzh; @@ -1494,15 +1494,15 @@ writezone(const char *const name, const char *const string) } } for (pass = 1; pass <= 2; ++pass) { - register int thistimei, thistimecnt; - register int thisleapi, thisleapcnt; - register int thistimelim, thisleaplim; - int writetype[TZ_MAX_TIMES]; - int typemap[TZ_MAX_TYPES]; - register int thistypecnt; - char thischars[TZ_MAX_CHARS]; - char thischarcnt; - int indmap[TZ_MAX_CHARS]; + int thistimei, thistimecnt; + int thisleapi, thisleapcnt; + int thistimelim, thisleaplim; + int writetype[TZ_MAX_TIMES]; + int typemap[TZ_MAX_TYPES]; + int thistypecnt; + char thischars[TZ_MAX_CHARS]; + char thischarcnt; + int indmap[TZ_MAX_CHARS]; if (pass == 1) { thistimei = timei32; @@ -1546,7 +1546,7 @@ writezone(const char *const name, const char *const string) ** set correctly). */ { - register int mrudst, mrustd, hidst, histd, type; + int mrudst, mrustd, hidst, histd, type; hidst = histd = mrudst = mrustd = -1; for (i = thistimei; i < thistimelim; ++i) @@ -1590,7 +1590,7 @@ writezone(const char *const name, const char *const string) indmap[i] = -1; thischarcnt = 0; for (i = 0; i < typecnt; ++i) { - register char * thisabbr; + char * thisabbr; if (!writetype[i]) continue; @@ -1647,7 +1647,7 @@ writezone(const char *const name, const char *const string) (void) fwrite(thischars, sizeof thischars[0], thischarcnt, fp); for (i = thisleapi; i < thisleaplim; ++i) { - register zic_t todo; + zic_t todo; if (roll[i]) { if (timecnt == 0 || trans[i] < ats[0]) { @@ -1690,9 +1690,9 @@ static void doabbr(char *const abbr, const char *const format, const char *const letters, const int isdst, const int doquotes) { - register char * cp; - register char * slashp; - register int len; + char * cp; + char * slashp; + int len; slashp = strchr(format, '/'); if (slashp == NULL) { @@ -1734,9 +1734,9 @@ updateminmax(const int x) static int stringoffset(char *result, long offset) { - register int hours; - register int minutes; - register int seconds; + int hours; + int minutes; + int seconds; result[0] = '\0'; if (offset < 0) { @@ -1765,11 +1765,11 @@ static int stringrule(char *result, const struct rule *const rp, const long dstoff, const long gmtoff) { - register long tod; + long tod; result = end(result); if (rp->r_dycode == DC_DOM) { - register int month, total; + int month, total; if (rp->r_dayofmonth == 29 && rp->r_month == TM_FEBRUARY) return -1; @@ -1778,7 +1778,7 @@ stringrule(char *result, const struct rule *const rp, const long dstoff, total += len_months[0][month]; (void) sprintf(result, "J%d", total + rp->r_dayofmonth); } else { - register int week; + int week; if (rp->r_dycode == DC_DOWGEQ) { if ((rp->r_dayofmonth % DAYSPERWEEK) != 1) @@ -1816,12 +1816,12 @@ stringrule(char *result, const struct rule *const rp, const long dstoff, static void stringzone(char *result, const struct zone *const zpfirst, const int zonecount) { - register const struct zone * zp; - register struct rule * rp; - register struct rule * stdrp; - register struct rule * dstrp; - register int i; - register const char * abbrvar; + const struct zone * zp; + struct rule * rp; + struct rule * stdrp; + struct rule * dstrp; + int i; + const char * abbrvar; result[0] = '\0'; zp = zpfirst + zonecount - 1; @@ -1896,24 +1896,24 @@ stringzone(char *result, const struct zone *const zpfirst, const int zonecount) static void outzone(const struct zone * const zpfirst, const int zonecount) { - register const struct zone * zp; - register struct rule * rp; - register int i, j; - register int usestart, useuntil; - register zic_t starttime, untiltime; - register long gmtoff; - register long stdoff; - register int year; - register long startoff; - register int startttisstd; - register int startttisgmt; - register int type; - register char * startbuf; - register char * ab; - register char * envvar; - register int max_abbr_len; - register int max_envvar_len; - register int prodstic; /* all rules are min to max */ + const struct zone * zp; + struct rule * rp; + int i, j; + int usestart, useuntil; + zic_t starttime, untiltime; + long gmtoff; + long stdoff; + int year; + long startoff; + int startttisstd; + int startttisgmt; + int type; + char * startbuf; + char * ab; + char * envvar; + int max_abbr_len; + int max_envvar_len; + int prodstic; /* all rules are min to max */ max_abbr_len = 2 + max_format_len + max_abbrvar_len; max_envvar_len = 2 * max_abbr_len + 5 * 9; @@ -1959,7 +1959,7 @@ outzone(const struct zone * const zpfirst, const int zonecount) */ stringzone(envvar, zpfirst, zonecount); if (noise && envvar[0] == '\0') { - register char * wp; + char * wp; wp = ecpyalloc(_("no POSIX environment variable for zone")); wp = ecatalloc(wp, " "); @@ -2037,9 +2037,9 @@ wp = ecpyalloc(_("no POSIX environment variable for zone")); rp->r_temp = rpytime(rp, year); } for ( ; ; ) { - register int k; - register zic_t jtime, ktime; - register long offset; + int k; + zic_t jtime, ktime; + long offset; INITIALIZE(ktime); if (useuntil) { @@ -2184,7 +2184,7 @@ static int addtype(const long gmtoff, const char *const abbr, const int isdst, const int ttisstd, const int ttisgmt) { - register int i, j; + int i, j; if (isdst != TRUE && isdst != FALSE) { error(_("internal error - addtype called with bad isdst")); @@ -2239,7 +2239,7 @@ addtype(const long gmtoff, const char *const abbr, const int isdst, static void leapadd(const zic_t t, const int positive, const int rolling, int count) { - register int i, j; + int i, j; if (leapcnt + (positive ? count : 1) > TZ_MAX_LEAPS) { error(_("too many leap seconds")); @@ -2269,8 +2269,8 @@ leapadd(const zic_t t, const int positive, const int rolling, int count) static void adjleap(void) { - register int i; - register long last = 0; + int i; + long last = 0; /* ** propagate leap seconds forward @@ -2314,7 +2314,7 @@ lowerit(int a) /* case-insensitive equality */ static ATTRIBUTE_PURE int -ciequal(register const char *ap, register const char *bp) +ciequal(const char *ap, const char *bp) { while (lowerit(*ap) == lowerit(*bp++)) if (*ap++ == '\0') @@ -2323,7 +2323,7 @@ ciequal(register const char *ap, register const char *bp) } static ATTRIBUTE_PURE int -itsabbr(register const char *abbr, register const char *word) +itsabbr(const char *abbr, const char *word) { if (lowerit(*abbr) != lowerit(*word)) return FALSE; @@ -2337,11 +2337,11 @@ itsabbr(register const char *abbr, register const char *word) } static ATTRIBUTE_PURE const struct lookup * -byword(register const char *const word, - register const struct lookup *const table) +byword(const char *const word, + const struct lookup *const table) { - register const struct lookup * foundlp; - register const struct lookup * lp; + const struct lookup * foundlp; + const struct lookup * lp; if (word == NULL || table == NULL) return NULL; @@ -2365,11 +2365,11 @@ byword(register const char *const word, } static char ** -getfields(register char *cp) +getfields(char *cp) { - register char * dp; - register char ** array; - register int nsubs; + char * dp; + char ** array; + int nsubs; if (cp == NULL) return NULL; @@ -2434,11 +2434,11 @@ tadd(const zic_t t1, const long t2) */ static zic_t -rpytime(register const struct rule *const rp, register const int wantedy) +rpytime(const struct rule *const rp, const int wantedy) { - register int y, m, i; - register long dayoff; /* with a nod to Margaret O. */ - register zic_t t; + int y, m, i; + long dayoff; /* with a nod to Margaret O. */ + zic_t t; if (wantedy == INT_MIN) return min_time; @@ -2474,7 +2474,7 @@ rpytime(register const struct rule *const rp, register const int wantedy) --i; dayoff = oadd(dayoff, eitol(i)); if (rp->r_dycode == DC_DOWGEQ || rp->r_dycode == DC_DOWLEQ) { - register long wday; + long wday; #define LDAYSPERWEEK ((long) DAYSPERWEEK) wday = eitol(EPOCH_WDAY); @@ -2517,11 +2517,11 @@ will not work with pre-2004 versions of zic")); static void newabbr(const char *const string) { - register int i; + int i; if (strcmp(string, GRANDPARENTED) != 0) { - register const char * cp; - const char * mp; + const char * cp; + const char * mp; /* ** Want one to ZIC_MAX_ABBR_LEN_WO_WARN alphabetics @@ -2569,8 +2569,8 @@ mp = _("time zone abbreviation differs from POSIX standard"); static int mkdirs(char *argname) { - register char * name; - register char * cp; + char * name; + char * cp; if (argname == NULL || *argname == '\0') return 0; -- 1.7.9.5
participants (1)
-
Paul Eggert