Get the clock of the RTC device in linux

Source: Internet
Author: User

Because of the differences between linux and windows, this struct cannot use the tm struct in the library file.

Code

# 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 \ n ",
Tm. tm_year + 1900,
Tm. tm_mon + 1,
Tm. tm_mday,
Tm. tm_hour,
Tm. tm_min,
Tm. tm_sec );
}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.