| TIMESPEC_GET(3) | Library Functions Manual | TIMESPEC_GET(3) |
timespec_get,
timespec_getres — get
current calendar time
Standard C Library (libc, -lc)
#include
<time.h>
int
timespec_get(struct
timespec *ts, int
base);
int
timespec_getres(struct
timespec *ts, int
base);
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).
These functions return the passed non-zero value of base if successful, otherwise 0 on failure.
The timespec_get() function with a
base of TIME_UTC conforms to
ISO/IEC 9899:2011 (“ISO C11”).
The base of TIME_MONOTONIC is
specified in ISO/IEC 9899:2024
(“ISO C23”).
The timespec_getres() function conforms to
ISO/IEC 9899:2024
(“ISO C23”).
The timespec_get() function first appeared
in NetBSD 8.0.
The timespec_getres() function first
appeared in NetBSD 11.0.
Kamil Rytarowski
<kamil@NetBSD.org>
Nia Alarie
<nia@NetBSD.org>
| April 22, 2025 | NetBSD 11.0 |