xref: /netbsd-src/share/man/man3/timeradd.3 (revision 7f21db1c0118155e0dd40b75182e30c589d9f63e)
1.\" $NetBSD: timeradd.3,v 1.2 2010/01/24 12:58:37 jruoho Exp $
2.\" Copyright (c) 1999 Kelly Yancey <kbyanc@posi.net>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. Neither the name of the author nor the names of any co-contributors
14.\"    may be used to endorse or promote products derived from this software
15.\"    without specific prior written permission.
16.\"
17.\" THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
18.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27.\" SUCH DAMAGE.
28.\"
29.\" $FreeBSD: src/share/man/man3/timeradd.3,v 1.3 2003/09/08 19:57:19 ru Exp $
30.\"
31.Dd January 24, 2010
32.Dt TIMERADD 3
33.Os
34.Sh NAME
35.Nm timeradd ,
36.Nm timersub ,
37.Nm timerclear ,
38.Nm timerisset ,
39.Nm timercmp
40.Nd operations on timevals
41.Sh SYNOPSIS
42.In sys/time.h
43.Ft void
44.Fn timeradd "struct timeval *a" "struct timeval *b" "struct timeval *res"
45.Ft void
46.Fn timersub "struct timeval *a" "struct timeval *b" "struct timeval *res"
47.Ft void
48.Fn timerclear "struct timeval *tvp"
49.Ft int
50.Fn timerisset "struct timeval *tvp"
51.Ft int
52.Fn timercmp "struct timeval *a" "struct timeval *b" CMP
53.Sh DESCRIPTION
54These macros are provided for manipulating
55.Fa timeval
56structures for use with the
57.Xr gettimeofday 2
58and
59.Xr settimeofday 2
60calls.
61The structure is defined in
62.In sys/time.h
63as:
64.Bd -literal
65struct timeval {
66	time_t		tv_sec;		/* seconds */
67	suseconds_t	tv_usec;	/* and microseconds */
68};
69.Ed
70.Pp
71.Fn timeradd
72adds the time information stored in
73.Fa a
74to
75.Fa b
76and stores the resulting
77.Vt timeval
78in
79.Fa res .
80The results are simplified such that the value of
81.Fa res->tv_usec
82is always less than 1,000,000 (1 second).
83.Pp
84.Fn timersub
85subtracts the time information stored in
86.Fa b
87from
88.Fa a
89and stores the resulting
90.Vt timeval
91in
92.Fa res .
93.Pp
94.Fn timerclear
95initializes
96.Fa tvp
97to midnight (0 hour) January 1st, 1970 (the Epoch).
98.Pp
99.Fn timerisset
100returns true if
101.Fa tvp
102is set to any time value other than the Epoch.
103.Pp
104.Fn timercmp
105compares
106.Fa a
107to
108.Fa b
109using the comparison operator given in
110.Fa CMP ,
111and returns the result of that comparison.
112.Sh SEE ALSO
113.Xr gettimeofday 2
114.Sh HISTORY
115The
116.Fn timeradd
117family of macros first appeared in
118.Nx 1.1 .
119These were later ported to
120.Fx 2.2.6 .
121