set a clock
#include <time.h> int clock_settime( clockid_t clock_id, struct timespec *tp );
The clock_settime() function sets the clock specified by clock_id, from the buffer pointed to by tp. The only supported clock ID is CLOCK_REALTIME, which maintains the system time.
The tp parameter points to a structure containing at least the following members:
/* This program sets the clock forward 1 day. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <time.h> int main( void ) { struct timespec stime; if( clock_gettime( CLOCK_REALTIME, &stime) == -1 ) { perror( "getclock" ); exit( EXIT_FAILURE ); } stime.tv_sec += (60*60)*24L; /* Add one day */ stime.tv_nsec = 0; if( clock_settime( CLOCK_REALTIME, &stime) == -1 ) { perror( "setclock" ); exit( EXIT_FAILURE ); } return( EXIT_SUCCESS ); }
POSIX 1003.4
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |
clock_getres(), clock_gettime(), clock_setres(), errno, qnx_getclock(), qnx_setclock(), ticksize utility