From 06358b9771fb9c3c7cb58b7a8185edd2b15ff236 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 10 Jun 2017 00:45:25 +0200 Subject: Fix Epoch computation * i386/i386at/rtc.c (CENTURY_START): New macro. (readtodc): Use CENTURY_START instead of assuming it is equal to 1970, and set yr to an absolute date before calling yeartoday. --- i386/i386at/rtc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/i386/i386at/rtc.c b/i386/i386at/rtc.c index b284c332..e9bd31e5 100644 --- a/i386/i386at/rtc.c +++ b/i386/i386at/rtc.c @@ -53,6 +53,10 @@ WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +/* time of day stored in RTC are currently between 1970 and 2070. Update that + * before 2070 please. */ +#define CENTURY_START 1970 + static boolean_t first_rtcopen_ever = TRUE; void @@ -163,7 +167,7 @@ readtodc(u_int *tp) dom = hexdectodec(rtclk.rtc_dom); mon = hexdectodec(rtclk.rtc_mon); yr = hexdectodec(rtclk.rtc_yr); - yr = (yr < 70) ? yr+100 : yr; + yr = (yr < CENTURY_START%100) ? yr+CENTURY_START+100 : yr+CENTURY_START; n = sec + 60 * min + 3600 * hr; n += (dom - 1) * 3600 * 24; @@ -173,7 +177,8 @@ readtodc(u_int *tp) for (i = mon - 2; i >= 0; i--) days += month[i]; month[1] = 28; - for (i = 70; i < yr; i++) + /* Epoch shall be 1970 January 1st */ + for (i = 1970; i < yr; i++) days += yeartoday(i); n += days * 3600 * 24; @@ -208,6 +213,7 @@ writetodc(void) n = (time.tv_sec - diff) / (3600 * 24); /* days */ rtclk.rtc_dow = (n + 4) % 7; /* 1/1/70 is Thursday */ + /* Epoch shall be 1970 January 1st */ for (j = 1970, i = yeartoday(j); n >= i; j++, i = yeartoday(j)) n -= i; -- cgit v1.2.3