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.
This commit is contained in:
parent
56c6b90cb6
commit
c6e81f25a5
1 changed files with 7 additions and 7 deletions
14
rtc_linux.c
14
rtc_linux.c
|
@ -297,10 +297,10 @@ slew_samples
|
||||||
whether the user runs his RTC on the local time zone or UTC */
|
whether the user runs his RTC on the local time zone or UTC */
|
||||||
|
|
||||||
static void
|
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;
|
struct tm *rtc_tm;
|
||||||
if (rtc_on_utc) {
|
if (utc) {
|
||||||
rtc_tm = gmtime(t);
|
rtc_tm = gmtime(t);
|
||||||
} else {
|
} else {
|
||||||
rtc_tm = localtime(t);
|
rtc_tm = localtime(t);
|
||||||
|
@ -352,7 +352,7 @@ rtc_from_t(const time_t *t, struct rtc_time *rtc_raw)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static time_t
|
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;
|
struct tm rtc_tm, temp1, temp2, *tm;
|
||||||
long diff;
|
long diff;
|
||||||
|
@ -372,7 +372,7 @@ t_from_rtc(struct rtc_time *rtc_raw)
|
||||||
|
|
||||||
t1 = mktime(&temp1);
|
t1 = mktime(&temp1);
|
||||||
|
|
||||||
tm = rtc_on_utc ? gmtime(&t1) : localtime(&t1);
|
tm = utc ? gmtime(&t1) : localtime(&t1);
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
DEBUG_LOG("gmtime()/localtime() failed");
|
DEBUG_LOG("gmtime()/localtime() failed");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -610,7 +610,7 @@ set_rtc(time_t new_rtc_time)
|
||||||
struct rtc_time rtc_raw;
|
struct rtc_time rtc_raw;
|
||||||
int status;
|
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);
|
status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
|
@ -805,7 +805,7 @@ read_from_device(int fd_, int event, void *any)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert RTC time into a struct timespec */
|
/* 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)) {
|
if (rtc_t == (time_t)(-1)) {
|
||||||
error = 1;
|
error = 1;
|
||||||
|
@ -955,7 +955,7 @@ RTC_Linux_TimePreInit(time_t driftfile_time)
|
||||||
|
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
/* Convert to seconds since 1970 */
|
/* 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)) {
|
if (rtc_t != (time_t)(-1)) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue