mirror of git://git.suckless.org/ubase
Use rtc_time
This commit is contained in:
parent
dacfb76c75
commit
e3d7ffa05c
28
hwclock.c
28
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
|
||||
|
|
22
rtc.h
22
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 */
|
||||
|
|
Loading…
Reference in New Issue