TIMESPEC_GET(3)

NAME
timespec_get, timespec_getres - get current calendar time

LIBRARY
libc

SYNOPSIS
#include <time.h>
int
timespec_get(struct timespec *ts, int base);
int
timespec_getres(struct timespec *ts, int base);

DESCRIPTION
The timespec_get() function sets the interval pointed to by ts to hold the current calendar time based on the specified time base in base. It is the ISO C equivalent to the POSIX function clock_gettime(2).

The base TIME_UTC returns the time since the epoch. This time is expressed in seconds and nanoseconds since midnight (0 hour), January 1, 1970. In NetBSD, this corresponds to CLOCK_REALTIME.

The base TIME_MONOTONIC returns the seconds and nanoseconds since an implementation-defined reference point in such a way that a second call will never return a value less than the first. In NetBSD, this corresponds to CLOCK_MONOTONIC.

The resolution of each timer can be queried using timespec_getres(). Each successive call to this function will return the same value for a specific clock. It is the ISO C equivalent to the POSIX function clock_getres(2).

RETURN VALUES
These functions return the passed non-zero value of base if successful, otherwise 0 on failure.

SEE ALSO
clock_gettime(2), gettimeofday(2), time(3)

STANDARDS
The timespec_get() function with a base of TIME_UTC conforms to isoC-2011. The base of TIME_MONOTONIC is specified in isoC-2023.

The timespec_getres() function conforms to isoC-2023.

HISTORY
The timespec_get() function first appeared in NetBSD 8.0.

The timespec_getres() function first appeared in NetBSD 11.0.

AUTHORS
Kamil Rytarowski <kamil@NetBSD.org> Nia Alarie <nia@NetBSD.org>