Deleted Added
full compact
3c3
< ** 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
---
> ** 1996-06-05 by Arthur David Olson.
9c9
< static char elsieid[] __unused = "@(#)localtime.c 7.78";
---
> static char elsieid[] __unused = "@(#)localtime.c 8.9";
12c12
< __FBSDID("$FreeBSD: head/lib/libc/stdtime/localtime.c 177824 2008-04-01 06:56:11Z davidxu $");
---
> __FBSDID("$FreeBSD: head/lib/libc/stdtime/localtime.c 192625 2009-05-23 06:31:50Z edwin $");
15,17c15,16
< ** Leap second handling from Bradley White (bww@k.gp.cs.cmu.edu).
< ** POSIX-style TZ environment variable handling from Guy Harris
< ** (guy@auspex.com).
---
> ** Leap second handling from Bradley White.
> ** POSIX-style TZ environment variable handling from Guy Harris.
30a30
> #include "float.h" /* for FLT_MAX and DBL_MAX */
31a32,44
> #ifndef TZ_ABBR_MAX_LEN
> #define TZ_ABBR_MAX_LEN 16
> #endif /* !defined TZ_ABBR_MAX_LEN */
>
> #ifndef TZ_ABBR_CHAR_SET
> #define TZ_ABBR_CHAR_SET \
> "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._"
> #endif /* !defined TZ_ABBR_CHAR_SET */
>
> #ifndef TZ_ABBR_ERR_CHAR
> #define TZ_ABBR_ERR_CHAR '_'
> #endif /* !defined TZ_ABBR_ERR_CHAR */
>
77c90
< ** WILDABBR is used. Another possibility: initialize tzname[0] to the
---
> ** WILDABBR is used. Another possibility: initialize tzname[0] to the
79c92
< ** And another: initialize tzname[0] to "ERA", with an explanation in the
---
> ** And another: initialize tzname[0] to "ERA", with an explanation in the
86c99
< static char wildabbr[] = "WILDABBR";
---
> static char wildabbr[] = WILDABBR;
132a146,147
> int goback;
> int goahead;
157a173,174
> static time_t detzcode64(const char * codep);
> static int differ_by_repeat(time_t t1, time_t t0);
158a176
> static const char * getqzname(const char * strp, const int delim);
165c183
< static void gmtsub(const time_t * timep, long offset,
---
> static struct tm * gmtsub(const time_t * timep, long offset,
167c185
< static void localsub(const time_t * timep, long offset,
---
> static struct tm * localsub(const time_t * timep, long offset,
169a188,191
> static int leaps_thru_end_of(int y);
> static int long_increment_overflow(long * number, int delta);
> static int long_normalize_overflow(long * tensptr,
> int * unitsptr, int base);
174c196
< void(*funcp) (const time_t *,
---
> struct tm * (*funcp)(const time_t *,
178c200
< void(*funcp) (const time_t *,
---
> struct tm * (*funcp)(const time_t *,
182c204
< void(*funcp) (const time_t *,
---
> struct tm * (*funcp)(const time_t *,
185c207
< static void timesub(const time_t * timep, long offset,
---
> static struct tm * timesub(const time_t * timep, long offset,
191c213,215
< static int tzload(const char * name, struct state * sp);
---
> static int typesequiv(const struct state * sp, int a, int b);
> static int tzload(const char * name, struct state * sp,
> int doextend);
227c251
< ** Thanks to Paul Eggert (eggert@twinsun.com) for noting this.
---
> ** Thanks to Paul Eggert for noting this.
248c272
< result = (codep[0] & 0x80) ? ~0L : 0L;
---
> result = (codep[0] & 0x80) ? ~0L : 0;
253a278,290
> static time_t
> detzcode64(codep)
> const char * const codep;
> {
> register time_t result;
> register int i;
>
> result = (codep[0] & 0x80) ? (~(int_fast64_t) 0) : 0;
> for (i = 0; i < 8; ++i)
> result = result * 256 + (codep[i] & 0xff);
> return result;
> }
>
301a339,356
> /*
> ** Finally, scrub the abbreviations.
> ** First, replace bogus characters.
> */
> for (i = 0; i < sp->charcnt; ++i)
> if (strchr(TZ_ABBR_CHAR_SET, sp->chars[i]) == NULL)
> sp->chars[i] = TZ_ABBR_ERR_CHAR;
> /*
> ** 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];
>
> if (strlen(cp) > TZ_ABBR_MAX_LEN &&
> strcmp(cp, GRANDPARENTED) != 0)
> *(cp + TZ_ABBR_MAX_LEN) = '\0';
> }
305c360,375
< tzload(name, sp)
---
> differ_by_repeat(t1, t0)
> const time_t t1;
> const time_t t0;
> {
> int_fast64_t _t0 = t0;
> int_fast64_t _t1 = t1;
>
> if (TYPE_INTEGRAL(time_t) &&
> TYPE_BIT(time_t) - TYPE_SIGNED(time_t) < SECSPERREPEAT_BITS)
> return 0;
> //turn ((int_fast64_t)(t1 - t0) == SECSPERREPEAT);
> return _t1 - _t0 == SECSPERREPEAT;
> }
>
> static int
> tzload(name, sp, doextend)
307a378
> register const int doextend;
311a383,390
> int stored;
> int nread;
> union {
> struct tzhead tzhead;
> char buf[2 * sizeof(struct tzhead) +
> 2 * sizeof *sp +
> 4 * TZ_MAX_TIMES];
> } u;
359,364c438,441
< {
< struct tzhead * tzhp;
< union {
< struct tzhead tzhead;
< char buf[sizeof *sp + sizeof *tzhp];
< } u;
---
> nread = _read(fid, u.buf, sizeof u.buf);
> if (_close(fid) < 0 || nread <= 0)
> return -1;
> for (stored = 4; stored <= 8; stored *= 2) {
368,370d444
< i = _read(fid, u.buf, sizeof u.buf);
< if (_close(fid) != 0)
< return -1;
385c459,460
< if (i - (p - u.buf) < sp->timecnt * 4 + /* ats */
---
> if (nread - (p - u.buf) <
> sp->timecnt * stored + /* ats */
387c462
< sp->typecnt * (4 + 2) + /* ttinfos */
---
> sp->typecnt * 6 + /* ttinfos */
389c464
< sp->leapcnt * (4 + 4) + /* lsinfos */
---
> sp->leapcnt * (stored + 4) + /* lsinfos */
394,395c469,471
< sp->ats[i] = detzcode(p);
< p += 4;
---
> sp->ats[i] = (stored == 4) ?
> detzcode(p) : detzcode64(p);
> p += stored;
423,424c499,501
< lsisp->ls_trans = detzcode(p);
< p += 4;
---
> lsisp->ls_trans = (stored == 4) ?
> detzcode(p) : detzcode64(p);
> p += stored;
453a531,570
> /*
> ** Out-of-sort ats should mean we're running on a
> ** signed time_t system but using a data file with
> ** unsigned values (or vice versa).
> */
> for (i = 0; i < sp->timecnt - 2; ++i)
> if (sp->ats[i] > sp->ats[i + 1]) {
> ++i;
> if (TYPE_SIGNED(time_t)) {
> /*
> ** Ignore the end (easy).
> */
> sp->timecnt = i;
> } else {
> /*
> ** Ignore the beginning (harder).
> */
> register int j;
>
> for (j = 0; j + i < sp->timecnt; ++j) {
> sp->ats[j] = sp->ats[j + i];
> sp->types[j] = sp->types[j + i];
> }
> sp->timecnt = j;
> }
> break;
> }
> /*
> ** If this is an old file, we're done.
> */
> if (u.tzhead.tzh_version[0] == '\0')
> break;
> nread -= p - u.buf;
> for (i = 0; i < nread; ++i)
> u.buf[i] = p[i];
> /*
> ** If this is a narrow integer time_t system, we're done.
> */
> if (stored >= (int) sizeof(time_t) && TYPE_INTEGRAL(time_t))
> break;
454a572,623
> if (doextend && nread > 2 &&
> u.buf[0] == '\n' && u.buf[nread - 1] == '\n' &&
> sp->typecnt + 2 <= TZ_MAX_TYPES) {
> struct state ts;
> register int result;
>
> u.buf[nread - 1] = '\0';
> result = tzparse(&u.buf[1], &ts, FALSE);
> if (result == 0 && ts.typecnt == 2 &&
> sp->charcnt + ts.charcnt <= TZ_MAX_CHARS) {
> for (i = 0; i < 2; ++i)
> ts.ttis[i].tt_abbrind +=
> sp->charcnt;
> for (i = 0; i < ts.charcnt; ++i)
> sp->chars[sp->charcnt++] =
> ts.chars[i];
> i = 0;
> while (i < ts.timecnt &&
> ts.ats[i] <=
> sp->ats[sp->timecnt - 1])
> ++i;
> while (i < ts.timecnt &&
> sp->timecnt < TZ_MAX_TIMES) {
> sp->ats[sp->timecnt] =
> ts.ats[i];
> sp->types[sp->timecnt] =
> sp->typecnt +
> ts.types[i];
> ++sp->timecnt;
> ++i;
> }
> sp->ttis[sp->typecnt++] = ts.ttis[0];
> sp->ttis[sp->typecnt++] = ts.ttis[1];
> }
> }
> sp->goback = sp->goahead = FALSE;
> if (sp->timecnt > 1) {
> for (i = 1; i < sp->timecnt; ++i)
> if (typesequiv(sp, sp->types[i], sp->types[0]) &&
> differ_by_repeat(sp->ats[i], sp->ats[0])) {
> sp->goback = TRUE;
> break;
> }
> for (i = sp->timecnt - 2; i >= 0; --i)
> if (typesequiv(sp, sp->types[sp->timecnt - 1],
> sp->types[i]) &&
> differ_by_repeat(sp->ats[sp->timecnt - 1],
> sp->ats[i])) {
> sp->goahead = TRUE;
> break;
> }
> }
457a627,651
> static int
> typesequiv(sp, a, b)
> const struct state * const sp;
> const int a;
> const int b;
> {
> register 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];
> result = ap->tt_gmtoff == bp->tt_gmtoff &&
> ap->tt_isdst == bp->tt_isdst &&
> ap->tt_ttisstd == bp->tt_ttisstd &&
> ap->tt_ttisgmt == bp->tt_ttisgmt &&
> strcmp(&sp->chars[ap->tt_abbrind],
> &sp->chars[bp->tt_abbrind]) == 0;
> }
> return result;
> }
>
469c663
< ** a valid character in a zone name is found. Return a pointer to that
---
> ** a valid character in a zone name is found. Return a pointer to that
485a680,698
> ** Given a pointer into an extended time zone string, scan until the ending
> ** delimiter of the zone name is located. Return a pointer to the delimiter.
> **
> ** As with getzname above, the legal character set is actually quite
> ** restricted, with other characters producing undefined results.
> ** We don't do any checking here; checking is done later in common-case code.
> */
>
> static const char *
> getqzname(register const char *strp, const int delim)
> {
> register int c;
>
> while ((c = *strp) != '\0' && c != delim)
> ++strp;
> return strp;
> }
>
> /*
550c763
< /* `SECSPERMIN' allows for leap seconds. */
---
> /* `SECSPERMIN' allows for leap seconds. */
589c802
< ** date[/time]. See POSIX section 8 for the format of "date" and "time".
---
> ** date[/time]. See POSIX section 8 for the format of "date" and "time".
708c921
< ** "dow" is the day-of-week of the first day of the month. Get
---
> ** "dow" is the day-of-week of the first day of the month. Get
731c944
< ** question. To get the Epoch-relative time of the specified local
---
> ** question. To get the Epoch-relative time of the specified local
769,772c982,993
< name = getzname(name);
< stdlen = name - stdname;
< if (stdlen < 3)
< return -1;
---
> if (*name == '<') {
> name++;
> stdname = name;
> name = getqzname(name, '>');
> if (*name != '>')
> return (-1);
> stdlen = name - stdname;
> name++;
> } else {
> name = getzname(name);
> stdlen = name - stdname;
> }
781c1002
< load_result = tzload(TZDEFRULES, sp);
---
> load_result = tzload(TZDEFRULES, sp, FALSE);
785,789c1006,1017
< dstname = name;
< name = getzname(name);
< dstlen = name - dstname; /* length of DST zone name */
< if (dstlen < 3)
< return -1;
---
> if (*name == '<') {
> dstname = ++name;
> name = getqzname(name, '>');
> if (*name != '>')
> return -1;
> dstlen = name - dstname;
> name++;
> } else {
> dstname = name;
> name = getzname(name);
> dstlen = name - dstname; /* length of DST zone name */
> }
816c1044
< ** Two transitions per year, from EPOCH_YEAR to 2037.
---
> ** Two transitions per year, from EPOCH_YEAR forward.
818,820d1045
< sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1);
< if (sp->timecnt > TZ_MAX_TIMES)
< return -1;
830c1055,1060
< for (year = EPOCH_YEAR; year <= 2037; ++year) {
---
> sp->timecnt = 0;
> for (year = EPOCH_YEAR;
> sp->timecnt + 2 <= TZ_MAX_TIMES;
> ++year) {
> time_t newfirst;
>
846c1076,1078
< janfirst += year_lengths[isleap(year)] *
---
> sp->timecnt += 2;
> newfirst = janfirst;
> newfirst += year_lengths[isleap(year)] *
847a1080,1082
> if (newfirst <= janfirst)
> break;
> janfirst = newfirst;
962c1197
< if (tzload(gmt, sp) != 0)
---
> if (tzload(gmt, sp, TRUE) != 0)
993c1228
< if (tzload((char *) NULL, lclptr) != 0)
---
> if (tzload((char *) NULL, lclptr, TRUE) != 0)
1056c1291
< } else if (tzload(name, lclptr) != 0)
---
> } else if (tzload(name, lclptr, TRUE) != 0)
1075c1310
< ** freely called. (And no, the PANS doesn't require the above behavior--
---
> ** freely called. (And no, the PANS doesn't require the above behavior--
1082c1317
< static void
---
> static struct tm *
1091c1326,1327
< const time_t t = *timep;
---
> struct tm * result;
> const time_t t = *timep;
1095,1098c1331,1332
< if (sp == NULL) {
< gmtsub(timep, offset, tmp);
< return;
< }
---
> if (sp == NULL)
> return gmtsub(timep, offset, tmp);
1099a1334,1372
> 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;
>
> if (t < sp->ats[0])
> seconds = sp->ats[0] - t;
> else seconds = t - sp->ats[sp->timecnt - 1];
> --seconds;
> tcycles = seconds / YEARSPERREPEAT / AVGSECSPERYEAR;
> ++tcycles;
> icycles = tcycles;
> if (tcycles - icycles >= 1 || icycles - tcycles >= 1)
> return NULL;
> seconds = icycles;
> seconds *= YEARSPERREPEAT;
> seconds *= AVGSECSPERYEAR;
> if (t < sp->ats[0])
> newt += seconds;
> else newt -= seconds;
> if (newt < sp->ats[0] ||
> newt > sp->ats[sp->timecnt - 1])
> return NULL; /* "cannot happen" */
> result = localsub(&newt, offset, tmp);
> if (result == tmp) {
> register time_t newy;
>
> newy = tmp->tm_year;
> if (t < sp->ats[0])
> newy -= icycles * YEARSPERREPEAT;
> else newy += icycles * YEARSPERREPEAT;
> tmp->tm_year = newy;
> if (tmp->tm_year != newy)
> return NULL;
> }
> return result;
> }
1108,1111c1381,1391
< for (i = 1; i < sp->timecnt; ++i)
< if (t < sp->ats[i])
< break;
< i = sp->types[i - 1];
---
> register int lo = 1;
> register int hi = sp->timecnt;
>
> while (lo < hi) {
> register int mid = (lo + hi) >> 1;
>
> if (t < sp->ats[mid])
> hi = mid;
> else lo = mid + 1;
> }
> i = (int) sp->types[lo - 1];
1120c1400
< timesub(&t, ttisp->tt_gmtoff, sp, tmp);
---
> result = timesub(&t, ttisp->tt_gmtoff, sp, tmp);
1125a1406
> return result;
1171c1452
< localtime_r(timep, tm)
---
> localtime_r(timep, tmp)
1173c1454
< struct tm * tm;
---
> struct tm * tmp;
1177c1458
< localsub(timep, 0L, tm);
---
> localsub(timep, 0L, tmp);
1179c1460
< return tm;
---
> return tmp;
1186c1467
< static void
---
> static struct tm *
1191a1473,1474
> register struct tm * result;
>
1204c1487
< timesub(timep, offset, gmtptr, tmp);
---
> result = timesub(timep, offset, gmtptr, tmp);
1223a1507
> return result;
1270c1554
< gmtime_r(timep, tm)
---
> gmtime_r(timep, tmp)
1272c1556
< struct tm * tm;
---
> struct tm * tmp;
1274,1275c1558
< gmtsub(timep, 0L, tm);
< return tm;
---
> return gmtsub(timep, 0L, tmp);
1285,1286c1568
< gmtsub(timep, offset, &tm);
< return &tm;
---
> return gmtsub(timep, offset, &tm);
1291c1573,1586
< static void
---
> /*
> ** Return the number of leap years through the end of the given year
> ** where, to make the math easy, the answer for year zero is defined as zero.
> */
>
> static int
> leaps_thru_end_of(y)
> register const int y;
> {
> return (y >= 0) ? (y / 4 - y / 100 + y / 400) :
> -(leaps_thru_end_of(-(y + 1)) + 1);
> }
>
> static struct tm *
1299c1594,1595
< long days;
---
> time_t tdays;
> int idays; /* unsigned would be so 2003 */
1301,1302c1597
< long y;
< int yleap;
---
> int y;
1336,1344c1631,1653
< days = *timep / SECSPERDAY;
< rem = *timep % SECSPERDAY;
< #ifdef mc68k
< if (*timep == 0x80000000) {
< /*
< ** A 3B1 muffs the division on the most negative number.
< */
< days = -24855;
< rem = -11648;
---
> y = EPOCH_YEAR;
> 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;
>
> tdelta = tdays / DAYSPERLYEAR;
> idelta = tdelta;
> if (tdelta - idelta >= 1 || idelta - tdelta >= 1)
> return NULL;
> if (idelta == 0)
> idelta = (tdays < 0) ? -1 : 1;
> newy = y;
> if (increment_overflow(&newy, idelta))
> return NULL;
> leapdays = leaps_thru_end_of(newy - 1) -
> leaps_thru_end_of(y - 1);
> tdays -= ((time_t) newy - y) * DAYSPERNYEAR;
> tdays -= leapdays;
> y = newy;
1346,1347c1655,1666
< #endif /* defined mc68k */
< rem += (offset - corr);
---
> {
> register long seconds;
>
> seconds = tdays * SECSPERDAY + 0.5;
> tdays = seconds / SECSPERDAY;
> rem += seconds - tdays * SECSPERDAY;
> }
> /*
> ** Given the range, we can now fearlessly cast...
> */
> idays = tdays;
> rem += offset - corr;
1350c1669
< --days;
---
> --idays;
1354c1673
< ++days;
---
> ++idays;
1355a1675,1700
> while (idays < 0) {
> if (increment_overflow(&y, -1))
> return NULL;
> idays += year_lengths[isleap(y)];
> }
> while (idays >= year_lengths[isleap(y)]) {
> idays -= year_lengths[isleap(y)];
> if (increment_overflow(&y, 1))
> return NULL;
> }
> tmp->tm_year = y;
> if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE))
> return NULL;
> tmp->tm_yday = idays;
> /*
> ** The "extra" mods below avoid overflow problems.
> */
> tmp->tm_wday = EPOCH_WDAY +
> ((y - EPOCH_YEAR) % DAYSPERWEEK) *
> (DAYSPERNYEAR % DAYSPERWEEK) +
> leaps_thru_end_of(y - 1) -
> leaps_thru_end_of(EPOCH_YEAR - 1) +
> idays;
> tmp->tm_wday %= DAYSPERWEEK;
> if (tmp->tm_wday < 0)
> tmp->tm_wday += DAYSPERWEEK;
1357c1702
< rem = rem % SECSPERHOUR;
---
> rem %= SECSPERHOUR;
1361c1706
< ** representation. This uses "... ??:59:60" et seq.
---
> ** representation. This uses "... ??:59:60" et seq.
1364,1385c1709,1712
< tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK);
< if (tmp->tm_wday < 0)
< tmp->tm_wday += DAYSPERWEEK;
< y = EPOCH_YEAR;
< #define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
< while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
< long newy;
<
< newy = y + days / DAYSPERNYEAR;
< if (days < 0)
< --newy;
< days -= (newy - y) * DAYSPERNYEAR +
< LEAPS_THRU_END_OF(newy - 1) -
< LEAPS_THRU_END_OF(y - 1);
< y = newy;
< }
< tmp->tm_year = y - TM_YEAR_BASE;
< tmp->tm_yday = (int) days;
< ip = mon_lengths[yleap];
< for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon))
< days = days - (long) ip[tmp->tm_mon];
< tmp->tm_mday = (int) (days + 1);
---
> ip = mon_lengths[isleap(y)];
> for (tmp->tm_mon = 0; idays >= ip[tmp->tm_mon]; ++(tmp->tm_mon))
> idays -= ip[tmp->tm_mon];
> tmp->tm_mday = (int) (idays + 1);
1389a1717
> return tmp;
1399c1727
< ** to local time in the form of a string. It is equivalent to
---
> ** to local time in the form of a string. It is equivalent to
1410c1738
< struct tm tm;
---
> struct tm mytm;
1412c1740
< return asctime_r(localtime_r(timep, &tm), buf);
---
> return asctime_r(localtime_r(timep, &mytm), buf);
1419,1420c1747
< ** [kridle@xinet.com as of 1996-01-16.]
< ** It does a binary search of the time_t space. Since time_t's are
---
> ** It does a binary search of the time_t space. Since time_t's are
1430c1757
< ** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).
---
> ** Simplified normalize logic courtesy Paul Eggert.
1445a1773,1784
> long_increment_overflow(number, delta)
> long * number;
> int delta;
> {
> long number0;
>
> number0 = *number;
> *number += delta;
> return (*number < number0) != (delta < 0);
> }
>
> static int
1460a1800,1814
> long_normalize_overflow(tensptr, unitsptr, base)
> long * const tensptr;
> int * const unitsptr;
> const int base;
> {
> register int tensdelta;
>
> tensdelta = (*unitsptr >= 0) ?
> (*unitsptr / base) :
> (-1 - (-1 - *unitsptr) / base);
> *unitsptr -= tensdelta * base;
> return long_increment_overflow(tensptr, tensdelta);
> }
>
> static int
1479c1833
< void (* const funcp)(const time_t*, long, struct tm*);
---
> struct tm * (* const funcp)(const time_t*, long, struct tm*);
1486,1487c1840
< int bits;
< int i, j ;
---
> int i, j;
1489,1491c1842,1848
< time_t newt;
< time_t t;
< struct tm yourtm, mytm;
---
> long li;
> time_t lo;
> time_t hi;
> long y;
> time_t newt;
> time_t t;
> struct tm yourtm, mytm;
1504c1861,1862
< if (normalize_overflow(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR))
---
> y = yourtm.tm_year;
> if (long_normalize_overflow(&y, &yourtm.tm_mon, MONSPERYEAR))
1507c1865
< ** Turn yourtm.tm_year into an actual year number for now.
---
> ** Turn y into an actual year number for now.
1510c1868
< if (increment_overflow(&yourtm.tm_year, TM_YEAR_BASE))
---
> if (long_increment_overflow(&y, TM_YEAR_BASE))
1513c1871
< if (increment_overflow(&yourtm.tm_year, -1))
---
> if (long_increment_overflow(&y, -1))
1515,1516c1873,1874
< i = yourtm.tm_year + (1 < yourtm.tm_mon);
< yourtm.tm_mday += year_lengths[isleap(i)];
---
> li = y + (1 < yourtm.tm_mon);
> yourtm.tm_mday += year_lengths[isleap(li)];
1519,1521c1877,1879
< i = yourtm.tm_year + (1 < yourtm.tm_mon);
< yourtm.tm_mday -= year_lengths[isleap(i)];
< if (increment_overflow(&yourtm.tm_year, 1))
---
> li = y + (1 < yourtm.tm_mon);
> yourtm.tm_mday -= year_lengths[isleap(li)];
> if (long_increment_overflow(&y, 1))
1525c1883
< i = mon_lengths[isleap(yourtm.tm_year)][yourtm.tm_mon];
---
> i = mon_lengths[isleap(y)][yourtm.tm_mon];
1531c1889
< if (increment_overflow(&yourtm.tm_year, 1))
---
> if (long_increment_overflow(&y, 1))
1535c1893
< if (increment_overflow(&yourtm.tm_year, -TM_YEAR_BASE))
---
> if (long_increment_overflow(&y, -TM_YEAR_BASE))
1536a1895,1897
> yourtm.tm_year = y;
> if (yourtm.tm_year != y)
> return WRONG;
1542c1903
< else if (yourtm.tm_year + TM_YEAR_BASE < EPOCH_YEAR) {
---
> else if (y + TM_YEAR_BASE < EPOCH_YEAR) {
1560,1561c1921
< ** Divide the search space in half
< ** (this works whether time_t is signed or unsigned).
---
> ** Do a binary search (this works whatever time_t's type is).
1563,1575c1923,1936
< bits = TYPE_BIT(time_t) - 1;
< /*
< ** If we have more than this, we will overflow tm_year for tmcomp().
< ** We should really return an error if we cannot represent it.
< */
< if (bits > 48)
< bits = 48;
< /*
< ** If time_t is signed, then 0 is just above the median,
< ** assuming two's complement arithmetic.
< ** If time_t is unsigned, then (1 << bits) is just above the median.
< */
< t = TYPE_SIGNED(time_t) ? 0 : (((time_t) 1) << bits);
---
> if (!TYPE_SIGNED(time_t)) {
> lo = 0;
> hi = lo - 1;
> } else if (!TYPE_INTEGRAL(time_t)) {
> if (sizeof(time_t) > sizeof(float))
> hi = (time_t) DBL_MAX;
> else hi = (time_t) FLT_MAX;
> lo = -hi;
> } else {
> lo = 1;
> for (i = 0; i < (int) TYPE_BIT(time_t) - 1; ++i)
> lo *= 2;
> hi = -(lo + 1);
> }
1577,1578c1938,1950
< (*funcp)(&t, offset, &mytm);
< dir = tmcomp(&mytm, &yourtm);
---
> t = lo / 2 + hi / 2;
> if (t < lo)
> t = lo;
> else if (t > hi)
> t = hi;
> if ((*funcp)(&t, offset, &mytm) == NULL) {
> /*
> ** Assume that t is too extreme to be represented in
> ** a struct tm; arrange things so that it is less
> ** extreme on the next pass.
> */
> dir = (t > 0) ? 1 : -1;
> } else dir = tmcomp(&mytm, &yourtm);
1580c1952,1963
< if (bits-- < 0)
---
> if (t == lo) {
> ++t;
> if (t <= lo)
> return WRONG;
> ++lo;
> } else if (t == hi) {
> --t;
> if (t >= hi)
> return WRONG;
> --hi;
> }
> if (lo > hi)
1582,1586c1965,1967
< if (bits < 0)
< --t; /* may be needed if new t is minimal */
< else if (dir > 0)
< t -= ((time_t) 1) << bits;
< else t += ((time_t) 1) << bits;
---
> if (dir > 0)
> hi = t;
> else lo = t;
1597c1978,1979
< sp = (funcp == localsub) ? lclptr : gmtptr;
---
> sp = (const struct state *)
> ((funcp == localsub) ? lclptr : gmtptr);
1610c1992,1993
< (*funcp)(&newt, offset, &mytm);
---
> if ((*funcp)(&newt, offset, &mytm) == NULL)
> continue;
1629,1630c2012,2013
< (*funcp)(&t, offset, tmp);
< *okayp = TRUE;
---
> if ((*funcp)(&t, offset, tmp))
> *okayp = TRUE;
1637c2020
< void (* const funcp)(const time_t*, long, struct tm*);
---
> struct tm * (* const funcp)(const time_t*, long, struct tm*);
1655c2038
< void (* const funcp)(const time_t *, long, struct tm *);
---
> struct tm * (* const funcp)(const time_t *, long, struct tm *);
1673c2056
< ** PCTS code courtesy Grant Sullivan (grant@osf.org).
---
> ** PCTS code courtesy Grant Sullivan.
1690c2073
< sp = (funcp == localsub) ? lclptr : gmtptr;
---
> sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr);
1836c2219
< ** is not unique. For a negative leap second
---
> ** is not unique. For a negative leap second