summaryrefslogtreecommitdiff
path: root/elsie.nci.nih.gov/src/localtime.c
diff options
context:
space:
mode:
authorStuart Bishop <stuart@stuartbishop.net>2015-10-26 12:28:13 +0700
committerStuart Bishop <stuart@stuartbishop.net>2015-10-26 12:28:13 +0700
commit17fd77664afec0d2c803a950fbcb7584e06b3c7d (patch)
treeceb2dad58b70dc543223b3e90e95d5041089f6e1 /elsie.nci.nih.gov/src/localtime.c
parentd53e863459e1a61075af44209e3581636682a162 (diff)
downloadpytz-17fd77664afec0d2c803a950fbcb7584e06b3c7d.tar.gz
Import 2015g
Diffstat (limited to 'elsie.nci.nih.gov/src/localtime.c')
-rw-r--r--elsie.nci.nih.gov/src/localtime.c82
1 files changed, 49 insertions, 33 deletions
diff --git a/elsie.nci.nih.gov/src/localtime.c b/elsie.nci.nih.gov/src/localtime.c
index ded8f7b..e3bc763 100644
--- a/elsie.nci.nih.gov/src/localtime.c
+++ b/elsie.nci.nih.gov/src/localtime.c
@@ -194,12 +194,12 @@ char * tzname[2] = {
static struct tm tm;
#ifdef USG_COMPAT
-long timezone = 0;
-int daylight = 0;
+long timezone;
+int daylight;
#endif /* defined USG_COMPAT */
#ifdef ALTZONE
-long altzone = 0;
+long altzone;
#endif /* defined ALTZONE */
/* Initialize *S to a value based on GMTOFF, ISDST, and ABBRIND. */
@@ -556,11 +556,6 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
break;
nread -= p - up->buf;
memmove(up->buf, p, nread);
- /*
- ** If this is a signed narrow time_t system, we're done.
- */
- if (TYPE_SIGNED(time_t) && stored >= (int) sizeof(time_t))
- break;
}
if (doextend && nread > 2 &&
up->buf[0] == '\n' && up->buf[nread - 1] == '\n' &&
@@ -569,31 +564,52 @@ tzloadbody(char const *name, struct state *sp, bool doextend,
up->buf[nread - 1] = '\0';
if (tzparse(&up->buf[1], ts, false)
- && 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];
+ && ts->typecnt == 2) {
+
+ /* Attempt to reuse existing abbreviations.
+ Without this, America/Anchorage would stop
+ working after 2037 when TZ_MAX_CHARS is 50, as
+ sp->charcnt equals 42 (for LMT CAT CAWT CAPT AHST
+ AHDT YST AKDT AKST) and ts->charcnt equals 10
+ (for AKST AKDT). Reusing means sp->charcnt can
+ stay 42 in this example. */
+ int gotabbr = 0;
+ int charcnt = sp->charcnt;
+ for (i = 0; i < 2; i++) {
+ char *tsabbr = ts->chars + ts->ttis[i].tt_abbrind;
+ int j;
+ for (j = 0; j < charcnt; j++)
+ if (strcmp(sp->chars + j, tsabbr) == 0) {
+ ts->ttis[i].tt_abbrind = j;
+ gotabbr++;
+ break;
+ }
+ if (! (j < charcnt)) {
+ int tsabbrlen = strlen(tsabbr);
+ if (j + tsabbrlen < TZ_MAX_CHARS) {
+ strcpy(sp->chars + j, tsabbr);
+ charcnt = j + tsabbrlen + 1;
+ ts->ttis[i].tt_abbrind = j;
+ gotabbr++;
+ }
+ }
+ }
+ if (gotabbr == 2) {
+ sp->charcnt = charcnt;
+ for (i = 0; i < ts->timecnt; i++)
+ if (sp->ats[sp->timecnt - 1] < ts->ats[i])
+ break;
+ 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];
+ }
}
}
if (sp->timecnt > 1) {