return 0;
}
+/* Read the RTC time/date */
+static int rtc_get_time(int fd, struct rtc_time *rtc_tm)
+{
+ int rc;
+
+ rc = ioctl(fd, RTC_RD_TIME, rtc_tm);
+ if (rc == -1) {
+ perror("RTC_RD_TIME ioctl");
+ return -errno;
+ }
+
+ printf("Current RTC date/time: %04d-%02d-%02d %02d:%02d:%02d\n",
+ rtc_tm->tm_year + 1900, rtc_tm->tm_mon + 1, rtc_tm->tm_mday,
+ rtc_tm->tm_hour, rtc_tm->tm_min, rtc_tm->tm_sec);
+
+ return 0;
+}
+
static int rtc_test_uie(int fd)
{
unsigned long data;
unsigned long data;
int rc;
+ rc = rtc_get_time(fd, &rtc_tm);
+ if (rc < 0)
+ return rc;
+
/* Read the RTC time/date */
rc = ioctl(fd, RTC_RD_TIME, &rtc_tm);
if (rc == -1) {
exit(rc);
}
+ if (options.time) {
+ struct rtc_time rtc_tm;
+
+ rc = rtc_get_time(fd, &rtc_tm);
+ if (rc < 0)
+ exit(rc);
+ }
+
if (options.test) {
rc = rtc_test(fd);
if (rc < 0)
{0, 0, 0, 0, ARGP_BSM_STR, 0},
{"clear", 'c', 0, 0, "Clear \"voltage low\" event", 0},
{"dev", 'd', "path", 0, "RTC device path (optional)", 0},
- {"test", 't', 0, 0, "Test RTC", 0},
+ {"test", 'x', 0, 0, "Test RTC", 0},
+ {"time", 't', 0, 0, "Get RTC time", 0},
{"voltage-level", 'v', 0, 0, "Get battery backup voltage level", 0},
/*
* Add -h manually; OPTION_HIDDEN prevents it from appearing twice in --help.
argp_usage(state);
break;
case 't':
+ options.time = true;
+ break;
+ case 'x':
options.test = true;
break;
case 'v':