Advertisement
Guest User

Untitled

a guest
Nov 28th, 2010
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <time.h>
  4. #include <sys/time.h>
  5. #include <sys/ioctl.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <fcntl.h>
  9. #include <linux/rtc.h>
  10. #include <linux/ioctl.h>
  11.  
  12.  
  13.  
  14.  
  15. using namespace std;
  16.  
  17.  
  18. int main()
  19. {
  20.     struct rtc_time rtc_tm;
  21.     int rtc_fd;
  22.     int ret;
  23.     int retClose;
  24.  
  25.     rtc_tm.tm_mday = 31;
  26.     rtc_tm.tm_mon = 4;
  27.     rtc_tm.tm_year = 104;
  28.     rtc_tm.tm_hour = 2;
  29.     rtc_tm.tm_min = 30;
  30.     rtc_tm.tm_sec = 0;
  31.  
  32.     rtc_fd = open("/dev/rtc", O_RDONLY,0);
  33.     if (rtc_fd == -1)
  34.     {
  35.         printf("/dev/rtc open error\n");
  36.         printf("error code: %d\n", rtc_fd);
  37.         cin.get() ;
  38.         exit(1);
  39.     }
  40.  
  41.     printf("rtc_fd: %d\n", rtc_fd);
  42.  
  43.     ret = ioctl(rtc_fd, RTC_SET_TIME, &rtc_tm);
  44.     printf("RTC_SET_TIME: %d\n", _IOW('p', 0x0a, struct rtc_time));
  45.     if (ret == -1)
  46.     {
  47.         printf("rtc ioctl RTC_SET_TIME error\r\n");
  48.         printf("error code: %d\n", ret);
  49.         cin.get() ;
  50.         exit(1);
  51.     }
  52.  
  53.  
  54.     printf("ret: %d\n", ret);
  55.     retClose = close(rtc_fd);
  56.     printf("retClose: %d\n", retClose);
  57.     printf("no error\r\n");
  58.     cin.get() ;
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement