carta
timespecsub(3)

timespecsub3

Operations on timevals and timespecs

Part of timeradd(3).

Usage

void

void

void

int

int

void

void

void

int

int

Overview

These macros are provided for manipulating timeval and timespec structures for use with the clock_gettime(2), clock_settime(2), gettimeofday(2) and settimeofday(2) calls. The timeval structure is defined in ⟨sys/time.h⟩ as:

struct timeval {
	long	tv_sec;		/* seconds since Jan. 1, 1970 */
	long	tv_usec;	/* and microseconds */
};

And the timespec structure is defined in ⟨time.h⟩ as:

struct timespec {
	time_t tv_sec;		/* seconds */
	long   tv_nsec;		/* and nanoseconds */
};

timeradd() and timespecadd() add the time information stored in a to b and store the result in res. The results are simplified such that the value of res->tv_usec or res->tv_nsec is always less than 1 second.

timersub() and timespecsub() subtract the time information stored in b from a and store the result in res.

timerclear() and timespecclear() initialize their argument to midnight (0 hour) January 1st, 1970 (the Epoch).

timerisset() and timespecisset() return true if their argument is set to any time value other than the Epoch.

timercmp() and timespeccmp() compare a to b using the comparison operator given in CMP, and return the result of that comparison.

History

  • FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 14.3-RELEASE: the text shown here
  • FreeBSD 14.2-RELEASE to FreeBSD 14.0-RELEASE
  • FreeBSD 13.5-RELEASE
  • FreeBSD 13.4-RELEASE to FreeBSD 13.3-RELEASE
  • FreeBSD 13.2-RELEASE to FreeBSD 13.0-RELEASE
  • FreeBSD 12.4-RELEASE
  • FreeBSD 12.3-RELEASE
  • FreeBSD 12.2-RELEASE
  • FreeBSD 12.1-RELEASE
  • FreeBSD 12.0-RELEASE

History

The timeradd() family of macros were imported from NetBSD 1.1, and appeared in FreeBSD 2.2.6. The timespecadd() family of macros were imported from NetBSD 1.3 into FreeBSD 3.0, though they were not exposed to userland until FreeBSD 12.0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.