1 /* Real Time Clock Driver Test
2 * by: Benjamin Gaignard (benjamin.gaignard@linaro.org)
5 * gcc rtctest_setdate.c -o rtctest_setdate
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/rtc.h>
20 #include <sys/ioctl.h>
22 #include <sys/types.h>
28 static const char default_time[] = "00:00:00";
30 int main(int argc, char **argv)
33 struct rtc_time new, current;
34 const char *rtc, *date;
35 const char *time = default_time;
46 fprintf(stderr, "usage: rtctest_setdate <rtcdev> <DD-MM-YYYY> [HH:MM:SS]\n");
50 fd = open(rtc, O_RDONLY);
56 sscanf(date, "%d-%d-%d", &new.tm_mday, &new.tm_mon, &new.tm_year);
59 sscanf(time, "%d:%d:%d", &new.tm_hour, &new.tm_min, &new.tm_sec);
61 fprintf(stderr, "Test will set RTC date/time to %d-%d-%d, %02d:%02d:%02d.\n",
62 new.tm_mday, new.tm_mon + 1, new.tm_year + 1900,
63 new.tm_hour, new.tm_min, new.tm_sec);
65 /* Write the new date in RTC */
66 retval = ioctl(fd, RTC_SET_TIME, &new);
68 perror("RTC_SET_TIME ioctl");
74 retval = ioctl(fd, RTC_RD_TIME, ¤t);
76 perror("RTC_RD_TIME ioctl");
80 fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",
81 current.tm_mday, current.tm_mon + 1, current.tm_year + 1900,
82 current.tm_hour, current.tm_min, current.tm_sec);