擷取linux系統RTC裝置的時鐘

來源:互聯網
上載者:User

由於linux和windows的不同,這個結構體不能使用 庫檔案中的tm結構體

代碼

#include <sys/ioctl.h>

struct rtc_time {
 int tm_sec;
 int tm_min;
 int tm_hour;
 int tm_mday;
 int tm_mon;
 int tm_year;
 int tm_wday;
 int tm_yday;
 int tm_isdst;
};
#define RTC_MAGIC 'p'
#define RTC_RD_TIME  _IOR(RTC_MAGIC, 0x09, struct rtc_time) /* Read RTC time. */
#define RTC_SET_TIME _IOW(RTC_MAGIC, 0x0a, struct rtc_time) /* Set RTC time. */
void rtc_test(void)
{
 int fd;
 struct rtc_time tm;
 fd = open("/dev/rtc0",O_RDONLY); 
 if (fd < 0) {
  return;
 }
 if (0 != ioctl(fd,RTC_RD_TIME,&tm)){
  close(fd);
  return;
 }
 close(fd);

 printf("%d-%d:%d-%d:%d:%d\n",
  tm.tm_year+1900,
  tm.tm_mon+1,
  tm.tm_mday,
  tm.tm_hour,
  tm.tm_min,
  tm.tm_sec);
}

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.