Get or set a clock
#include <sys/neutrino.h> int ClockTime( clockid_t id, const uint64_t * new, uint64_t * old ); int ClockTime_r( clockid_t id, const uint64_t * new, uint64_t * old );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
You can use these kernel calls to:
The ClockTime() and ClockTime_r() functions are identical except in the way they indicate errors. See the Returns section for details.
If new isn't NULL, then it contains the absolute time, in nanoseconds, to set the system clock to. This affects the software clock maintained by the system. It doesn't change any underlying hardware clock that maintains the time when the system's power is turned off.
|You need to have superuser privileges to set the clock. You can set the time only when the id is CLOCK_REALTIME.|
If you call ClockTime() to set the time of day, the kernel checks to see if the SYSPAGE_ENTRY(qtime)->boot_time field is zero. If it is, the kernel sets it to the appropriate value. There's a -T option for all startup programs that prevents the setting of this field, so that the kernel will set it the first time you call ClockTime() to change the time of day. This is useful if the RTC hardware isn't in UTC.
Once set, the system time increments by some number of nanoseconds, based on the resolution of the system clock. You can query or change this resolution by using the ClockPeriod() kernel call.
These calls don't block.
The only difference between these functions is the way they indicate errors:
clock_gettime(), clock_settime(), ClockAdjust(), ClockPeriod(), SYSPAGE_ENTRY()
Clocks, Timers, and Getting a Kick Every So Often chapter of Getting Started with QNX Neutrino