Which clock is set by using stime() and clock_settime()? As I can read in man both can set a Linux time. Function stime() sets "the idea of time" and clock_settime() with parameter CLOCK_REALTIME can set a "system wide RTC".
1) What are these clocks?
2) Are there any differences?
3) Do they also set the HW clock?
4) If not: Does anybody know a smart way to set the hwclock in C/C++ without using ioctl()?
[Update 1]
More concrete point 4: What is the C equivalent for std::system("/sbin/hwclock -w")
?
Sorry for this short answer i actually just wanted to do a comment, but it wont allow me that.
Well to help you about your question 4. Some quick research on Google sent me to https://github.com/karelzak/util-linux/blob/master/sys-utils/hwclock.c I havent studied this code more than 2 minutes but a quick search showed line 468:
static void set_hardware_clock(const time_t newtime, const bool universal, const bool testing)
edit:
BTW Check out the wikipedia for it http://en.wikipedia.org/wiki/Util-linux and man rtc
I answer my question with the help provided by MrSykkox.
I read http://linux.die.net/man/4/rtc and had a look into the given sources of sys-utils. Both show me that there are a lot of different HW-clocks types like CMOS, RTC, KD and so on. In a part of sys-utils code I found some descriptors are set by opening some specific devices like /dev/rtc, /dev/rtc0, /dev/misc/rtc, /dev/port exclusive for reading. And of course I found the ioctl() stuff for setting the RTC.
Conclusion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With