struct tm tm;
/* Sync system clock from RTC; first, initialize the timezone fields of struct tm. */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
/* Override the main fields of struct tm, but not the timezone fields */
r = clock_get_hwclock(&tm);
log_debug_errno(r, "Failed to get hardware clock, ignoring: %m");
else {
/* And set the system clock with this */
- if (c->local_rtc)
- ts.tv_sec = mktime(&tm);
- else
- ts.tv_sec = timegm(&tm);
+ mktime_or_timegm(&tm, !c->local_rtc);
if (clock_settime(CLOCK_REALTIME, &ts) < 0)
log_debug_errno(errno, "Failed to update system clock, ignoring: %m");
struct tm tm;
/* Sync RTC from system clock */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
r = clock_set_hwclock(&tm);
if (r < 0)
}
/* Sync down to RTC */
- if (c->local_rtc)
- localtime_r(&ts.tv_sec, &tm);
- else
- gmtime_r(&ts.tv_sec, &tm);
+ localtime_or_gmtime_r(&ts.tv_sec, &tm, !c->local_rtc);
r = clock_set_hwclock(&tm);
if (r < 0)