CLOCK_GETTIME(3) BSD Programmer's Manual CLOCK_GETTIME(3)NAME
clock_gettime, clock_settime, clock_getres - get/set a POSIX clock
SYNOPSIS
#include <time.h>
int
clock_gettime(clockid_t which, struct timespec *curtime);
int
clock_settime(clockid_t which, struct timespec *curtime);
int
clock_getres(clockid_t which, struct timespec *resolution);
DESCRIPTION
The clock_gettime() function retrieves the current time as indicated by
the clock specified by the clock identifier which. Currently, which must
be set to CLOCK_REALTIME, as only that clock is supported. The result is
returned in curtime.
The clock_settime() function sets the value of the specified clock using
the value in curtime.
The CLOCK_REALTIME clock maintains the system time expressed in seconds
and nanoseconds since midnight (0 hour), January 1, 1970. The resolution
of the system clock is hardware dependent, and the time may be updated
continuously or periodically.
The platform specific resolution supported by the clock is returned by
the clock_getres() function.
The structures pointed to by curtime and resolution are defined in
<time.h> as:
struct timespec {
long tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
Only the super-user may set the time of day.
RETURN
A 0 return value indicates that the call succeeded, otherwise -1 is re-
turned and the global variable errno is set appropriately.
ERRORS
The clock_getres() function may fail and set errno for any of the errors
specified for the library function sysctl(2).
The clock_gettime() function may fail and set errno for any of the errors
specified for the library function gettimeofday(2).
The clock_settime() function may fail and set errno for any of the errors
specified for the library function settimeofday(3).
SEE ALSOgettimeofday(2), settimeofday(2), ctime(3)4th Berkeley Distribution May 3, 1996 1