From c6e81f25a5df63752f0043551233c7eb4575eff2 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 22 Jul 2024 13:40:59 +0200 Subject: [PATCH] rtc: pass info whether RTC is on UTC as a function parameter rtc_from_t() and t_from_rtc() call either gmtime or localtime depending on the value of a global rtc_on_utc variable. This will not be appropriate anymore when we start exporting functions that call rtc_from_t() and t_from_rtc() for use outside of rtc_linux.c as the rtc_on_utc variable may not have been initialized yet or at all. Therefore make whether the RTC is on UTC a function parameter of these functions, so the value can be propagated from the callers. --- rtc_linux.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7324d26..11e2baa 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -297,10 +297,10 @@ slew_samples whether the user runs his RTC on the local time zone or UTC */ static void -rtc_from_t(const time_t *t, struct rtc_time *rtc_raw) +rtc_from_t(const time_t *t, struct rtc_time *rtc_raw, int utc) { struct tm *rtc_tm; - if (rtc_on_utc) { + if (utc) { rtc_tm = gmtime(t); } else { rtc_tm = localtime(t); @@ -352,7 +352,7 @@ rtc_from_t(const time_t *t, struct rtc_time *rtc_raw) */ static time_t -t_from_rtc(struct rtc_time *rtc_raw) +t_from_rtc(struct rtc_time *rtc_raw, int utc) { struct tm rtc_tm, temp1, temp2, *tm; long diff; @@ -372,7 +372,7 @@ t_from_rtc(struct rtc_time *rtc_raw) t1 = mktime(&temp1); - tm = rtc_on_utc ? gmtime(&t1) : localtime(&t1); + tm = utc ? gmtime(&t1) : localtime(&t1); if (!tm) { DEBUG_LOG("gmtime()/localtime() failed"); return -1; @@ -610,7 +610,7 @@ set_rtc(time_t new_rtc_time) struct rtc_time rtc_raw; int status; - rtc_from_t(&new_rtc_time, &rtc_raw); + rtc_from_t(&new_rtc_time, &rtc_raw, rtc_on_utc); status = ioctl(fd, RTC_SET_TIME, &rtc_raw); if (status < 0) { @@ -805,7 +805,7 @@ read_from_device(int fd_, int event, void *any) } /* Convert RTC time into a struct timespec */ - rtc_t = t_from_rtc(&rtc_raw); + rtc_t = t_from_rtc(&rtc_raw, rtc_on_utc); if (rtc_t == (time_t)(-1)) { error = 1; @@ -955,7 +955,7 @@ RTC_Linux_TimePreInit(time_t driftfile_time) if (status >= 0) { /* Convert to seconds since 1970 */ - rtc_t = t_from_rtc(&rtc_raw); + rtc_t = t_from_rtc(&rtc_raw, rtc_on_utc); if (rtc_t != (time_t)(-1)) {