1 /* frontend to the readclock.drv driver for getting/setting hw clock. */
12 #include <minix/type.h>
13 #include <minix/const.h>
14 #include <minix/syslib.h>
15 #include <minix/sysutil.h>
16 #include <minix/com.h>
21 static void readclock(int type
, struct tm
*t
, int flags
);
27 main(int argc
, char **argv
)
29 int flags
= RTCDEV_NOFLAGS
;
30 int nflag
= 0; /* Tell what, but don't do it. */
31 int wflag
= 0; /* Set the CMOS clock. */
39 /* Process options. */
55 flags
|= RTCDEV_CMOSREG
;
56 wflag
= 1; /* -W implies -w */
59 flags
|= RTCDEV_Y2KBUG
;
71 /* Read the CMOS real time clock. */
72 for (i
= 0; i
< 10; i
++) {
73 readclock(RTCDEV_GET_TIME
, &time1
, flags
);
76 time1
.tm_isdst
= -1; /* Do timezone calculations. */
79 rtc
= mktime(&time1
); /* Transform to a time_t. */
84 ("readclock: Invalid time read from CMOS RTC: %d-%02d-%02d %02d:%02d:%02d\n",
85 time2
.tm_year
+ 1900, time2
.tm_mon
+ 1, time2
.tm_mday
,
86 time2
.tm_hour
, time2
.tm_min
, time2
.tm_sec
);
93 /* Set system time. */
96 printf("stime(%lu)\n", (unsigned long) rtc
);
98 if (stime(&rtc
) < 0) {
100 errmsg("Not allowed to set time.");
104 tmnow
= *localtime(&rtc
);
105 if (strftime(date
, sizeof(date
),
106 "%a %b %d %H:%M:%S %Z %Y", &tmnow
) != 0) {
109 if (!quiet
) printf("%s\n", date
);
112 /* Set the CMOS clock to the system time. */
113 tmnow
= *localtime(&now
);
116 printf("%04d-%02d-%02d %02d:%02d:%02d\n",
117 tmnow
.tm_year
+ 1900,
120 tmnow
.tm_hour
, tmnow
.tm_min
, tmnow
.tm_sec
);
122 readclock(RTCDEV_SET_TIME
, &tmnow
, flags
);
131 static char *prompt
= "readclock: ";
133 if (!quiet
) printf("%s%s\n", prompt
, s
);
138 readclock(int type
, struct tm
*t
, int flags
)
144 r
= minix_rs_lookup("readclock.drv", &ep
);
146 if (!quiet
) errmsg("Couldn't locate readclock.drv\n");
150 memset(&m
, 0, sizeof(m
));
151 m
.m_lc_readclock_rtcdev
.tm
= (vir_bytes
)t
;
152 m
.m_lc_readclock_rtcdev
.flags
= flags
;
154 r
= _syscall(ep
, type
, &m
);
155 if (r
!= RTCDEV_REPLY
|| m
.m_readclock_lc_rtcdev
.status
!= 0) {
156 if (!quiet
) errmsg("Call to readclock.drv failed\n");
164 if (!quiet
) printf("Usage: readclock [-nqwW2]\n");