summaryrefslogtreecommitdiff
path: root/lib/libc/time/localtime.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-01-11 17:46:33 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-01-11 17:46:33 +0000
commit7d5e7fb43d575c54a7fe0b995e331f39c260a642 (patch)
treeece2955b3cb32dd5f333d0e5c5b95ea2952371b4 /lib/libc/time/localtime.c
parent7f256c176b27a96548e19698117d1f933b47a4cd (diff)
from netbsd; sync with tzcode96a
Diffstat (limited to 'lib/libc/time/localtime.c')
-rw-r--r--lib/libc/time/localtime.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/lib/libc/time/localtime.c b/lib/libc/time/localtime.c
index 5014b3f8571..79f88efff09 100644
--- a/lib/libc/time/localtime.c
+++ b/lib/libc/time/localtime.c
@@ -1,8 +1,8 @@
-/* $NetBSD: localtime.c,v 1.4 1995/03/16 19:14:16 jtc Exp $ */
+/* $NetBSD: localtime.c,v 1.5 1996/01/08 22:50:55 jtc Exp $ */
#ifndef lint
#ifndef NOID
-static char elsieid[] = "@(#)localtime.c 7.43";
+static char elsieid[] = "@(#)localtime.c 7.50";
#endif /* !defined NOID */
#endif /* !defined lint */
@@ -214,8 +214,8 @@ const char * const codep;
static void
settzname P((void))
{
- register struct state * const sp = lclptr;
- register int i;
+ register struct state * const sp = lclptr;
+ register int i;
tzname[0] = wildabbr;
tzname[1] = wildabbr;
@@ -430,7 +430,7 @@ register const char * strp;
{
register char c;
- while ((c = *strp) != '\0' && !isdigit(c) && c != ',' && c != '-' &&
+ while ((c = *strp) != '\0' && !is_digit(c) && c != ',' && c != '-' &&
c != '+')
++strp;
return strp;
@@ -453,15 +453,15 @@ const int max;
register char c;
register int num;
- if (strp == NULL || !isdigit(*strp))
+ if (strp == NULL || !is_digit(c = *strp))
return NULL;
num = 0;
- while ((c = *strp) != '\0' && isdigit(c)) {
+ do {
num = num * 10 + (c - '0');
if (num > max)
return NULL; /* illegal value */
- ++strp;
- }
+ c = *++strp;
+ } while (is_digit(c));
if (num < min)
return NULL; /* illegal value */
*nump = num;
@@ -523,14 +523,13 @@ getoffset(strp, offsetp)
register const char * strp;
long * const offsetp;
{
- register int neg;
+ register int neg = 0;
if (*strp == '-') {
neg = 1;
++strp;
- } else if (isdigit(*strp) || *strp++ == '+')
- neg = 0;
- else return NULL; /* illegal offset */
+ } else if (*strp == '+')
+ ++strp;
strp = getsecs(strp, offsetp);
if (strp == NULL)
return NULL; /* illegal time */
@@ -575,7 +574,7 @@ register struct rule * const rulep;
if (*strp++ != '.')
return NULL;
strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1);
- } else if (isdigit(*strp)) {
+ } else if (is_digit(*strp)) {
/*
** Day of year.
*/
@@ -817,7 +816,8 @@ const int lastditch;
for (i = 0; i < sp->timecnt; ++i) {
j = sp->types[i];
if (!sp->ttis[j].tt_isdst) {
- theirstdoffset = -sp->ttis[j].tt_gmtoff;
+ theirstdoffset =
+ -sp->ttis[j].tt_gmtoff;
break;
}
}
@@ -825,7 +825,8 @@ const int lastditch;
for (i = 0; i < sp->timecnt; ++i) {
j = sp->types[i];
if (sp->ttis[j].tt_isdst) {
- theirdstoffset = -sp->ttis[j].tt_gmtoff;
+ theirdstoffset =
+ -sp->ttis[j].tt_gmtoff;
break;
}
}
@@ -1188,19 +1189,18 @@ register struct tm * const tmp;
if (tmp->tm_wday < 0)
tmp->tm_wday += DAYSPERWEEK;
y = EPOCH_YEAR;
- if (days >= 0)
- for ( ; ; ) {
- yleap = isleap(y);
- if (days < (long) year_lengths[yleap])
- break;
- ++y;
- days = days - (long) year_lengths[yleap];
- }
- else do {
- --y;
- yleap = isleap(y);
- days = days + (long) year_lengths[yleap];
- } while (days < 0);
+#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400)
+ while (days < 0 || days >= (long) year_lengths[yleap = isleap(y)]) {
+ register int 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];
@@ -1399,10 +1399,10 @@ int * const okayp;
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
- for (i = 0; i < sp->typecnt; ++i) {
+ for (i = sp->typecnt - 1; i >= 0; --i) {
if (sp->ttis[i].tt_isdst != yourtm.tm_isdst)
continue;
- for (j = 0; j < sp->typecnt; ++j) {
+ for (j = sp->typecnt - 1; j >= 0; --j) {
if (sp->ttis[j].tt_isdst == yourtm.tm_isdst)
continue;
newt = t + sp->ttis[j].tt_gmtoff -
@@ -1434,7 +1434,7 @@ label:
static time_t
time1(tmp, funcp, offset)
struct tm * const tmp;
-void (* const funcp) P((const time_t*, long, struct tm*));
+void (* const funcp) P((const time_t *, long, struct tm *));
const long offset;
{
register time_t t;
@@ -1473,10 +1473,10 @@ const long offset;
if (sp == NULL)
return WRONG;
#endif /* defined ALL_STATE */
- for (samei = 0; samei < sp->typecnt; ++samei) {
+ for (samei = sp->typecnt - 1; samei >= 0; --samei) {
if (sp->ttis[samei].tt_isdst != tmp->tm_isdst)
continue;
- for (otheri = 0; otheri < sp->typecnt; ++otheri) {
+ for (otheri = sp->typecnt - 1; otheri >= 0; --otheri) {
if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst)
continue;
tmp->tm_sec += sp->ttis[otheri].tt_gmtoff -