Deleted Added
full compact
3c3
< static char elsieid[] = "@(#)localtime.c 7.19";
---
> static char elsieid[] = "@(#)localtime.c 7.44";
19c19,21
< #define ACCESS_MODE O_RDONLY
---
> /*
> ** SunOS 4.1.1 headers lack O_BINARY.
> */
32c34
< ** or implicitly).
---
> ** or implicitly).
34c36
< ** or implicitly).
---
> ** or implicitly).
51c53
< static const char GMT[] = "GMT";
---
> static char wildabbr[] = "WILDABBR";
52a55,56
> static const char gmt[] = "GMT";
>
57a62
> int tt_ttisgmt; /* TRUE if transition is GMT */
82c87
< char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof GMT),
---
> char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS + 1, sizeof gmt),
119c124,126
< static time_t time1 P((struct tm * tmp, void (* funcp)(),
---
> static time_t time1 P((struct tm * tmp,
> void(*funcp) P((const time_t *,
> long, struct tm *)),
121c128,130
< static time_t time2 P((struct tm *tmp, void (* funcp)(),
---
> static time_t time2 P((struct tm *tmp,
> void(*funcp) P((const time_t *,
> long, struct tm*)),
144a154,158
> #ifndef TZ_STRLEN_MAX
> #define TZ_STRLEN_MAX 255
> #endif /* !defined TZ_STRLEN_MAX */
>
> static char lcl_TZname[TZ_STRLEN_MAX + 1];
149,150c163,164
< WILDABBR,
< WILDABBR
---
> wildabbr,
> wildabbr
152a167,176
> /*
> ** Section 4.12.3 of X3.159-1989 requires that
> ** Except for the strftime function, these functions [asctime,
> ** ctime, gmtime, localtime] return values in one of two static
> ** objects: a broken-down time structure and an array of char.
> ** Thanks to Paul Eggert (eggert@twinsun.com) for noting this.
> */
>
> static struct tm tm;
>
169c193
< result = 0;
---
> result = (codep[0] & 0x80) ? ~0L : 0L;
176c200
< settzname()
---
> settzname P((void))
178c202
< register const struct state * const sp = lclptr;
---
> register struct state * const sp = lclptr;
181,182c205,206
< tzname[0] = WILDABBR;
< tzname[1] = WILDABBR;
---
> tzname[0] = wildabbr;
> tzname[1] = wildabbr;
192c216
< tzname[0] = tzname[1] = GMT;
---
> tzname[0] = tzname[1] = gmt;
200c224
< (char *) &sp->chars[ttisp->tt_abbrind];
---
> &sp->chars[ttisp->tt_abbrind];
221c245
< (char *) &sp->chars[ttisp->tt_abbrind];
---
> &sp->chars[ttisp->tt_abbrind];
237c261,268
< register int doaccess;
---
> register int doaccess;
> /*
> ** Section 4.9.1 of the C standard says that
> ** "FILENAME_MAX expands to an integral constant expression
> ** that is the sie needed for an array of char large enough
> ** to hold the longest file name string that the implementation
> ** guarantees can be opened."
> */
258c289
< if (doaccess && access(name, ACCESS_MODE) != 0)
---
> if (doaccess && access(name, R_OK) != 0)
264,266c295,298
< register const struct tzhead * tzhp;
< char buf[sizeof *sp + sizeof *tzhp];
< int ttisstdcnt;
---
> struct tzhead * tzhp;
> char buf[sizeof *sp + sizeof *tzhp];
> int ttisstdcnt;
> int ttisgmtcnt;
269c301
< if (close(fid) != 0 || i < sizeof *tzhp)
---
> if (close(fid) != 0)
271,276c303,316
< tzhp = (struct tzhead *) buf;
< ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt);
< sp->leapcnt = (int) detzcode(tzhp->tzh_leapcnt);
< sp->timecnt = (int) detzcode(tzhp->tzh_timecnt);
< sp->typecnt = (int) detzcode(tzhp->tzh_typecnt);
< sp->charcnt = (int) detzcode(tzhp->tzh_charcnt);
---
> p = buf;
> p += sizeof tzhp->tzh_reserved;
> ttisstdcnt = (int) detzcode(p);
> p += 4;
> ttisgmtcnt = (int) detzcode(p);
> p += 4;
> sp->leapcnt = (int) detzcode(p);
> p += 4;
> sp->timecnt = (int) detzcode(p);
> p += 4;
> sp->typecnt = (int) detzcode(p);
> p += 4;
> sp->charcnt = (int) detzcode(p);
> p += 4;
281c321,322
< (ttisstdcnt != sp->typecnt && ttisstdcnt != 0))
---
> (ttisstdcnt != sp->typecnt && ttisstdcnt != 0) ||
> (ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
283,288c324,330
< if (i < sizeof *tzhp +
< sp->timecnt * (4 + sizeof (char)) +
< sp->typecnt * (4 + 2 * sizeof (char)) +
< sp->charcnt * sizeof (char) +
< sp->leapcnt * 2 * 4 +
< ttisstdcnt * sizeof (char))
---
> if (i - (p - buf) < sp->timecnt * 4 + /* ats */
> sp->timecnt + /* types */
> sp->typecnt * (4 + 2) + /* ttinfos */
> sp->charcnt + /* chars */
> sp->leapcnt * (4 + 4) + /* lsinfos */
> ttisstdcnt + /* ttisstds */
> ttisgmtcnt) /* ttisgmts */
290d331
< p = buf + sizeof *tzhp;
338a380,392
> for (i = 0; i < sp->typecnt; ++i) {
> register struct ttinfo * ttisp;
>
> ttisp = &sp->ttis[i];
> if (ttisgmtcnt == 0)
> ttisp->tt_ttisgmt = FALSE;
> else {
> ttisp->tt_ttisgmt = *p++;
> if (ttisp->tt_ttisgmt != TRUE &&
> ttisp->tt_ttisgmt != FALSE)
> return -1;
> }
> }
417c471,477
< strp = getnum(strp, &num, 0, HOURSPERDAY);
---
> /*
> ** `HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like
> ** "M10.4.6/26", which does not conform to Posix,
> ** but which specifies the equivalent of
> ** ``02:00 on the first Sunday on or after 23 Oct''.
> */
> strp = getnum(strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1);
420c480
< *secsp = num * SECSPERHOUR;
---
> *secsp = num * (long) SECSPERHOUR;
429c489,490
< strp = getnum(strp, &num, 0, SECSPERMIN - 1);
---
> /* `SECSPERMIN' allows for leap seconds. */
> strp = getnum(strp, &num, 0, SECSPERMIN);
538a600
> INITIALIZE(value);
629,630c691,692
< int stdlen;
< int dstlen;
---
> size_t stdlen;
> size_t dstlen;
637a700
> INITIALIZE(dstname);
724,729c787,790
< int sawstd;
< int sawdst;
< long stdfix;
< long dstfix;
< long oldfix;
< int isdst;
---
> register long theirstdoffset;
> register long theirdstoffset;
> register long theiroffset;
> register int isdst;
730a792
> register int j;
737,741c799
< ** Compute the difference between the real and
< ** prototype standard and summer time offsets
< ** from GMT, and put the real standard and summer
< ** time offsets into the rules in place of the
< ** prototype offsets.
---
> ** Initial values of theirstdoffset and theirdstoffset.
743,765c801,806
< sawstd = FALSE;
< sawdst = FALSE;
< stdfix = 0;
< dstfix = 0;
< for (i = 0; i < sp->typecnt; ++i) {
< if (sp->ttis[i].tt_isdst) {
< oldfix = dstfix;
< dstfix = sp->ttis[i].tt_gmtoff +
< dstoffset;
< if (sawdst && (oldfix != dstfix))
< return -1;
< sp->ttis[i].tt_gmtoff = -dstoffset;
< sp->ttis[i].tt_abbrind = stdlen + 1;
< sawdst = TRUE;
< } else {
< oldfix = stdfix;
< stdfix = sp->ttis[i].tt_gmtoff +
< stdoffset;
< if (sawstd && (oldfix != stdfix))
< return -1;
< sp->ttis[i].tt_gmtoff = -stdoffset;
< sp->ttis[i].tt_abbrind = 0;
< sawstd = TRUE;
---
> theirstdoffset = 0;
> for (i = 0; i < sp->timecnt; ++i) {
> j = sp->types[i];
> if (!sp->ttis[j].tt_isdst) {
> theirstdoffset = -sp->ttis[j].tt_gmtoff;
> break;
767a809,816
> theirdstoffset = 0;
> for (i = 0; i < sp->timecnt; ++i) {
> j = sp->types[i];
> if (sp->ttis[j].tt_isdst) {
> theirdstoffset = -sp->ttis[j].tt_gmtoff;
> break;
> }
> }
769c818
< ** Make sure we have both standard and summer time.
---
> ** Initially we're assumed to be in standard time.
771,772c820,821
< if (!sawdst || !sawstd)
< return -1;
---
> isdst = FALSE;
> theiroffset = theirstdoffset;
774,780c823,824
< ** Now correct the transition times by shifting
< ** them by the difference between the real and
< ** prototype offsets. Note that this difference
< ** can be different in standard and summer time;
< ** the prototype probably has a 1-hour difference
< ** between standard and summer time, but a different
< ** difference can be specified in TZ.
---
> ** Now juggle transition times and types
> ** tracking offsets as you do.
782d825
< isdst = FALSE; /* we start in standard time */
784,798c827,857
< register const struct ttinfo * ttisp;
<
< /*
< ** If summer time is in effect, and the
< ** transition time was not specified as
< ** standard time, add the summer time
< ** offset to the transition time;
< ** otherwise, add the standard time offset
< ** to the transition time.
< */
< ttisp = &sp->ttis[sp->types[i]];
< sp->ats[i] +=
< (isdst && !ttisp->tt_ttisstd) ?
< dstfix : stdfix;
< isdst = ttisp->tt_isdst;
---
> j = sp->types[i];
> sp->types[i] = sp->ttis[j].tt_isdst;
> if (sp->ttis[j].tt_ttisgmt) {
> /* No adjustment to transition time */
> } else {
> /*
> ** If summer time is in effect, and the
> ** transition time was not specified as
> ** standard time, add the summer time
> ** offset to the transition time;
> ** otherwise, add the standard time
> ** offset to the transition time.
> */
> /*
> ** Transitions from DST to DDST
> ** will effectively disappear since
> ** POSIX provides for only one DST
> ** offset.
> */
> if (isdst && !sp->ttis[j].tt_ttisstd) {
> sp->ats[i] += dstoffset -
> theirdstoffset;
> } else {
> sp->ats[i] += stdoffset -
> theirstdoffset;
> }
> }
> theiroffset = -sp->ttis[j].tt_gmtoff;
> if (sp->ttis[j].tt_isdst)
> theirdstoffset = theiroffset;
> else theirstdoffset = theiroffset;
799a859,868
> /*
> ** Finally, fill in ttis.
> ** ttisstd and ttisgmt need not be handled.
> */
> sp->ttis[0].tt_gmtoff = -stdoffset;
> sp->ttis[0].tt_isdst = FALSE;
> sp->ttis[0].tt_abbrind = 0;
> sp->ttis[1].tt_gmtoff = -dstoffset;
> sp->ttis[1].tt_isdst = TRUE;
> sp->ttis[1].tt_abbrind = stdlen + 1;
829,830c898,899
< if (tzload(GMT, sp) != 0)
< (void) tzparse(GMT, sp, TRUE);
---
> if (tzload(gmt, sp) != 0)
> (void) tzparse(gmt, sp, TRUE);
833a903,906
> /*
> ** A non-static declaration of tzsetwall in a system header file
> ** may cause a warning about this upcoming static declaration...
> */
837c910
< tzsetwall()
---
> tzsetwall P((void))
839c912,915
< lcl_is_set = TRUE;
---
> if (lcl_is_set < 0)
> return;
> lcl_is_set = -1;
>
855c931
< tzset()
---
> tzset P((void))
864c940,946
< lcl_is_set = TRUE;
---
>
> if (lcl_is_set > 0 && strcmp(lcl_TZname, name) == 0)
> return;
> lcl_is_set = (strlen(name) < sizeof(lcl_TZname));
> if (lcl_is_set)
> (void) strcpy(lcl_TZname, name);
>
882c964
< (void) strcpy(lclptr->chars, GMT);
---
> (void) strcpy(lclptr->chars, gmt);
905c987
< register const struct state * sp;
---
> register struct state * sp;
910,911d991
< if (!lcl_is_set)
< tzset();
941c1021
< tzname[tmp->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind];
---
> tzname[tmp->tm_isdst] = &sp->chars[ttisp->tt_abbrind];
943c1023
< tmp->TM_ZONE = (char *)&sp->chars[ttisp->tt_abbrind];
---
> tmp->TM_ZONE = &sp->chars[ttisp->tt_abbrind];
951,952c1031
< static struct tm tm;
<
---
> tzset();
983c1062
< tmp->TM_ZONE = WILDABBR;
---
> tmp->TM_ZONE = wildabbr;
987c1066
< tmp->TM_ZONE = GMT;
---
> tmp->TM_ZONE = gmt;
1001,1002d1079
< static struct tm tm;
<
1014,1015d1090
< static struct tm tm;
<
1077c1152
< #endif /* mc68k */
---
> #endif /* defined mc68k */
1129a1205,1210
> /*
> ** Section 4.12.3.2 of X3.159-1989 requires that
> ** The ctime funciton converts the calendar time pointed to by timer
> ** to local time in the form of a string. It is equivalent to
> ** asctime(localtime(timer))
> */
1155c1236
< int number0;
---
> int number0;
1196c1277
< void (* const funcp)();
---
> void (* const funcp) P((const time_t*, long, struct tm*));
1341c1422
< void (* const funcp)();
---
> void (* const funcp) P((const time_t*, long, struct tm*));
1403a1485
> tzset();
1478,1479d1559
< if (!lcl_is_set)
< (void) tzset();
1493a1574
> tzset();
1503a1585
> tzset();