From 0b320647bf85e8a258612ed7bf8f9165214db39d Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 20 May 1998 12:12:53 +0000 Subject: [PATCH] Update from glibc 2.1. --- time/offtime.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/time/offtime.c b/time/offtime.c index f13c8a38ae1..a3feb8f448d 100644 --- a/time/offtime.c +++ b/time/offtime.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1991, 1993, 1997 Free Software Foundation, Inc. +/* Copyright (C) 1991, 1993, 1997, 1998 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -26,15 +26,16 @@ extern const unsigned short int __mon_yday[2][13]; /* Compute the `struct tm' representation of *T, offset OFFSET seconds east of UTC, - and store year, yday, mon, mday, wday, hour, min, sec into *TP. */ -void + and store year, yday, mon, mday, wday, hour, min, sec into *TP. + Return nonzero if successful. */ +int __offtime (t, offset, tp) const time_t *t; long int offset; struct tm *tp; { - register long int days, rem, y; - register const unsigned short int *ip; + long int days, rem, y; + const unsigned short int *ip; days = *t / SECS_PER_DAY; rem = *t % SECS_PER_DAY; @@ -59,7 +60,8 @@ __offtime (t, offset, tp) tp->tm_wday += 7; y = 1970; -#define LEAPS_THRU_END_OF(y) ((y) / 4 - (y) / 100 + (y) / 400) +#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) +#define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) while (days < 0 || days >= (__isleap (y) ? 366 : 365)) { @@ -73,11 +75,14 @@ __offtime (t, offset, tp) y = yg; } tp->tm_year = y - 1900; + if (tp->tm_year != y - 1900) + return 0; tp->tm_yday = days; ip = __mon_yday[__isleap(y)]; - for (y = 11; days < ip[y]; --y) + for (y = 11; days < (long int) ip[y]; --y) continue; days -= ip[y]; tp->tm_mon = y; tp->tm_mday = days + 1; + return 1; } -- 2.47.2