Changeset View
Changeset View
Standalone View
Standalone View
share/man/man3/timeradd.3
Show All 21 Lines | |||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
.\" SUCH DAMAGE. | .\" SUCH DAMAGE. | ||||
.\" | .\" | ||||
.\" $FreeBSD$ | .\" $FreeBSD$ | ||||
.\" | .\" | ||||
.Dd August 11, 1999 | .Dd July 22, 2018 | ||||
.Dt TIMERADD 3 | .Dt TIMERADD 3 | ||||
.Os | .Os | ||||
.Sh NAME | .Sh NAME | ||||
.Nm timeradd , | .Nm timeradd , | ||||
.Nm timersub , | .Nm timersub , | ||||
.Nm timerclear , | .Nm timerclear , | ||||
.Nm timerisset , | .Nm timerisset , | ||||
.Nm timercmp | .Nm timercmp , | ||||
.Nd operations on timevals | .Nm timespecadd , | ||||
.Nm timespecsub , | |||||
.Nm timespecclear , | |||||
.Nm timespecisset , | |||||
.Nm timespeccmp | |||||
.Nd operations on timevals and timespecs | |||||
.Sh SYNOPSIS | .Sh SYNOPSIS | ||||
.In sys/time.h | .In sys/time.h | ||||
.Ft void | .Ft void | ||||
.Fn timeradd "struct timeval *a" "struct timeval *b" "struct timeval *res" | .Fn timeradd "struct timeval *a" "struct timeval *b" "struct timeval *res" | ||||
.Ft void | .Ft void | ||||
.Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res" | .Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res" | ||||
.Ft void | .Ft void | ||||
.Fn timerclear "struct timeval *tvp" | .Fn timerclear "struct timeval *tvp" | ||||
.Ft int | .Ft int | ||||
.Fn timerisset "struct timeval *tvp" | .Fn timerisset "struct timeval *tvp" | ||||
.Ft int | .Ft int | ||||
.Fn timercmp "struct timeval *a" "struct timeval *b" CMP | .Fn timercmp "struct timeval *a" "struct timeval *b" CMP | ||||
.Ft void | |||||
.Fn timespecadd "struct timespec *a" "struct timespec *b" "struct timespec *res" | |||||
.Ft void | |||||
.Fn timespecsub "struct timespec *a" "struct timespec *b" "struct timespec *res" | |||||
.Ft void | |||||
.Fn timespecclear "struct timespec *ts" | |||||
.Ft int | |||||
.Fn timespecisset "struct timespec *ts" | |||||
.Ft int | |||||
.Fn timespeccmp "struct timespec *a" "struct timespec *b" CMP | |||||
.Sh DESCRIPTION | .Sh DESCRIPTION | ||||
These macros are provided for manipulating | These macros are provided for manipulating | ||||
.Fa timeval | .Fa timeval | ||||
and | |||||
.Fa timespec | |||||
structures for use with the | structures for use with the | ||||
.Xr clock_gettime 2 , | |||||
.Xr clock_settime 2 , | |||||
.Xr gettimeofday 2 | .Xr gettimeofday 2 | ||||
and | and | ||||
.Xr settimeofday 2 | .Xr settimeofday 2 | ||||
calls. | calls. | ||||
The structure is defined in | The | ||||
.Fa timeval | |||||
structure is defined in | |||||
.In sys/time.h | .In sys/time.h | ||||
as: | as: | ||||
.Bd -literal | .Bd -literal | ||||
struct timeval { | struct timeval { | ||||
long tv_sec; /* seconds since Jan. 1, 1970 */ | long tv_sec; /* seconds since Jan. 1, 1970 */ | ||||
long tv_usec; /* and microseconds */ | long tv_usec; /* and microseconds */ | ||||
}; | }; | ||||
.Ed | .Ed | ||||
And the | |||||
.Fa timespec | |||||
structure is defined in | |||||
.In time.h | |||||
as: | |||||
.Bd -literal | |||||
struct timespec { | |||||
time_t tv_nsec; /* seconds */ | |||||
long tv_nsec; /* and nanoseconds */ | |||||
}; | |||||
.Ed | |||||
.Pp | .Pp | ||||
.Fn timeradd | .Fn timeradd | ||||
adds the time information stored in | and | ||||
.Fn timespecadd | |||||
add the time information stored in | |||||
.Fa a | .Fa a | ||||
to | to | ||||
.Fa b | .Fa b | ||||
and stores the resulting | and store the result in | ||||
.Vt timeval | |||||
in | |||||
.Fa res . | .Fa res . | ||||
The results are simplified such that the value of | The results are simplified such that the value of | ||||
.Fa res->tv_usec | .Fa res->tv_usec | ||||
is always less than 1,000,000 (1 second). | or | ||||
.Fa res->tv_nsec | |||||
is always less than 1 second. | |||||
.Pp | .Pp | ||||
.Fn timersub | .Fn timersub | ||||
subtracts the time information stored in | and | ||||
.Fn timespecsub | |||||
subtract the time information stored in | |||||
.Fa b | .Fa b | ||||
from | from | ||||
.Fa a | .Fa a | ||||
and stores the resulting | and store the result | ||||
.Vt timeval | |||||
in | in | ||||
.Fa res . | .Fa res . | ||||
.Pp | .Pp | ||||
.Fn timerclear | .Fn timerclear | ||||
initializes | and | ||||
.Fa tvp | .Fn timespecclear | ||||
to midnight (0 hour) January 1st, 1970 (the Epoch). | initialize their argument to midnight (0 hour) January 1st, 1970 (the Epoch). | ||||
.Pp | .Pp | ||||
.Fn timerisset | .Fn timerisset | ||||
returns true if | and | ||||
.Fa tvp | .Fn timespecisset | ||||
is set to any time value other than the Epoch. | return true if their argument is set to any time value other than the Epoch. | ||||
.Pp | .Pp | ||||
.Fn timercmp | .Fn timercmp | ||||
compares | and | ||||
.Fn timespeccmp | |||||
compare | |||||
.Fa a | .Fa a | ||||
to | to | ||||
.Fa b | .Fa b | ||||
using the comparison operator given in | using the comparison operator given in | ||||
.Fa CMP , | .Fa CMP , | ||||
and returns the result of that comparison. | and return the result of that comparison. | ||||
.Sh SEE ALSO | .Sh SEE ALSO | ||||
.Xr gettimeofday 2 | .Xr gettimeofday 2 , | ||||
.Xr clock_gettime 2 | |||||
.Sh HISTORY | .Sh HISTORY | ||||
The | The | ||||
.Fn timeradd | .Fn timeradd | ||||
family of macros were imported from | family of macros were imported from | ||||
.Nx 1.1 , | .Nx 1.1 , | ||||
and appeared in | and appeared in | ||||
.Fx 2.2.6 . | .Fx 2.2.6 . | ||||
The | |||||
.Fn timespecadd | |||||
family of macros were imported from | |||||
.Nx 1.3 | |||||
into | |||||
.Fx 3.0 , | |||||
though they were not exposed to userland until | |||||
.Fx 12.0 . |