#include #include #include #include #include #include #include #include #include #include struct linux_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_SET_TIME _IOW('p', 0x0a, struct linux_rtc_time) /* Set RTC time */ #define RTC_RD_TIME _IOR('p', 0x09, struct linux_rtc_time) /* Read RTC time */ int main() { int rtc; struct tm tm; time_t t; struct timeval tv = { 0, 0 }; struct timezone tz = { 0, 0 }; int utc = 1; if ( gettimeofday ( &tv, &tz )) printf( "gettimeofday() failed" ); t = tv.tv_sec; return 0; if (( rtc = open ( "/dev/rtc0", O_WRONLY )) < 0 ) { if (( rtc = open ( "/dev/misc/rtc0", O_WRONLY )) < 0 ) printf( "Could not access RTC" ); } tm = *( utc ? gmtime ( &t ) : localtime ( &t )); tm.tm_isdst = 0; if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) printf( "Could not set the RTC time" ); close ( rtc ); return 0; }