Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <sys/time.h>
- #include <sys/ioctl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <linux/rtc.h>
- #include <linux/ioctl.h>
- using namespace std;
- int main()
- {
- struct rtc_time rtc_tm;
- int rtc_fd;
- int ret;
- int retClose;
- rtc_tm.tm_mday = 31;
- rtc_tm.tm_mon = 4;
- rtc_tm.tm_year = 104;
- rtc_tm.tm_hour = 2;
- rtc_tm.tm_min = 30;
- rtc_tm.tm_sec = 0;
- rtc_fd = open("/dev/rtc", O_RDONLY,0);
- if (rtc_fd == -1)
- {
- printf("/dev/rtc open error\n");
- printf("error code: %d\n", rtc_fd);
- cin.get() ;
- exit(1);
- }
- printf("rtc_fd: %d\n", rtc_fd);
- ret = ioctl(rtc_fd, RTC_SET_TIME, &rtc_tm);
- printf("RTC_SET_TIME: %d\n", _IOW('p', 0x0a, struct rtc_time));
- if (ret == -1)
- {
- printf("rtc ioctl RTC_SET_TIME error\r\n");
- printf("error code: %d\n", ret);
- cin.get() ;
- exit(1);
- }
- printf("ret: %d\n", ret);
- retClose = close(rtc_fd);
- printf("retClose: %d\n", retClose);
- printf("no error\r\n");
- cin.get() ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement