OpenBSD manual page server

Manual Page Search Parameters

TIMERADD(3) Library Functions Manual TIMERADD(3)

timerclear, timerisset, timerisvalid, timercmp, timersub, timeradd, timespecclear, timespecisset, timespecisvalid, timespeccmp, timespecsub, timespecadd, TIMEVAL_TO_TIMESPEC, TIMESPEC_TO_TIMEVALmanipulate time structures

#include <sys/time.h>

void
timerclear(struct timeval *a);

int
timerisset(struct timeval *a);

int
timerisvalid(struct timeval *a);

int
timercmp(struct timeval *a, struct timeval *b, operator);

void
timersub(struct timeval *a, struct timeval *b, struct timeval *c);

void
timeradd(struct timeval *a, struct timeval *b, struct timeval *c);

void
timespecclear(struct timespec *a);

int
timespecisset(struct timespec *a);

int
timespecisvalid(struct timespec *a);

int
timespeccmp(struct timespec *a, struct timespec *b, operator);

void
timespecsub(struct timespec *a, struct timespec *b, struct timespec *c);

void
timespecadd(struct timespec *a, struct timespec *b, struct timespec *c);

void
TIMEVAL_TO_TIMESPEC(struct timeval *tv, struct timespec *ts);

void
TIMESPEC_TO_TIMEVAL(struct timeval *tv, struct timespec *ts);

The () and () macros defined in <sys/time.h> simplify the use of timeval and timespec structures, respectively.

The following macros are available:

(a), (a)
Set the time value in a to zero.
(a), (a)
Test if the time value in a is non-zero.
(a)
Test if the microsecond value in a is greater than or equal to zero and less than one million.
(a)
Test if the nanosecond value in a is greater than or equal to zero and less than one billion.
(a, b, operator), (a, b, operator)
Test if the expression a operator b is true, where operator is one of <, <=, ==, !=, >=, or >.
(a, b, c), (a, b, c)
Subtract b from a and store the result in c.
(a, b, c), (a, b, c)
Add b to a and store the result in c.
(tv, ts)
Convert tv to a struct timespec and store the result in ts.
(tv, ts)
Convert ts to a struct timeval and store the result in tv.

The macros returning int return 1 if the tested condition holds or 0 otherwise.

adjtime(2), clock_gettime(2), futex(2), futimens(2), futimes(2), getitimer(2), gettimeofday(2), kevent(2), nanosleep(2), ppoll(2), pselect(2)

These macros are non-standard, though many systems offer them. Similar interfaces are often available in their absence.

The macros timerclear(), timerisset(), and timercmp() first appeared in 4.1cBSD, TIMEVAL_TO_TIMESPEC() and TIMESPEC_TO_TIMEVAL() in 4.4BSD, timersub() and timeradd() in NetBSD 1.1, and timerisvalid() in OpenBSD 6.5.

The argument ordering for TIMESPEC_TO_TIMEVAL() is unintuitive.

May 10, 2019 OpenBSD-7.3