commit e3d7ffa05c8b658cf79e406baa3dcfe111fe4928
parent dacfb76c75bbd9a5020d4a3bd22b993e1e9dfebd
Author: sin <sin@2f30.org>
Date: Tue, 3 Jun 2014 15:04:53 +0100
Use rtc_time
Diffstat:
M | hwclock.c | | | 28 | +++++++++++++++++++++++++--- |
M | rtc.h | | | 22 | ++++++++++++++++++++-- |
2 files changed, 45 insertions(+), 5 deletions(-)
diff --git a/hwclock.c b/hwclock.c
@@ -77,14 +77,36 @@ echotime(char *dev)
static void
readrtctm(struct tm *tm, int fd)
{
- memset(tm, 0, sizeof(*tm));
- ioctl(fd, RTC_RD_TIME, tm);
+ struct rtc_time rt;
+
+ memset(&rt, 0, sizeof(rt));
+ ioctl(fd, RTC_RD_TIME, &rt);
+ tm->tm_sec = rt.tm_sec;
+ tm->tm_min = rt.tm_min;
+ tm->tm_hour = rt.tm_hour;
+ tm->tm_mday = rt.tm_mday;
+ tm->tm_mon = rt.tm_mon;
+ tm->tm_year = rt.tm_year;
+ tm->tm_wday = rt.tm_wday;
+ tm->tm_yday = rt.tm_yday;
+ tm->tm_isdst = rt.tm_isdst;
}
static void
writertctm(struct tm *tm, int fd)
{
- ioctl(fd, RTC_SET_TIME, tm);
+ struct rtc_time rt;
+
+ rt.tm_sec = tm->tm_sec;
+ rt.tm_min = tm->tm_min;
+ rt.tm_hour = tm->tm_hour;
+ rt.tm_mday = tm->tm_mday;
+ rt.tm_mon = tm->tm_mon;
+ rt.tm_year = tm->tm_year;
+ rt.tm_wday = tm->tm_wday;
+ rt.tm_yday = tm->tm_yday;
+ rt.tm_isdst = tm->tm_isdst;
+ ioctl(fd, RTC_SET_TIME, &rt);
}
static void
diff --git a/rtc.h b/rtc.h
@@ -1,2 +1,20 @@
-#define RTC_RD_TIME _IOR('p', 0x09, struct tm) /* Read RTC time */
-#define RTC_SET_TIME _IOW('p', 0x0a, struct tm) /* Set RTC time */
+/*
+ * The struct used to pass data via the following ioctl. Similar to the
+ * struct tm in <time.h>, but it needs to be here so that the kernel
+ * source is self contained, allowing cross-compiles, etc. etc.
+ */
+
+struct rtc_time {
+ int tm_sec;
+ int tm_min;
+ int tm_hour;
+ int tm_mday;
+ int tm_mon;
+ int tm_year;
+ int tm_wday;
+ int tm_yday;
+ int tm_isdst;
+};
+
+#define RTC_RD_TIME _IOR('p', 0x09, struct rtc_time) /* Read RTC time */
+#define RTC_SET_TIME _IOW('p', 0x0a, struct rtc_time) /* Set RTC time */