@@@ much mess, mostly manpages
[mLib] / sys / tv.3.in
CommitLineData
b6b9d458 1.\" -*-nroff-*-
c4ccbbf9
MW
2.\"
3.\" Manual for timeval arithmetic
4.\"
5.\" (c) 1999, 2001, 2005, 2009, 2024 Straylight/Edgeware
6.\"
7.
8.\"----- Licensing notice ---------------------------------------------------
9.\"
10.\" This file is part of the mLib utilities library.
11.\"
12.\" mLib is free software: you can redistribute it and/or modify it under
13.\" the terms of the GNU Library General Public License as published by
14.\" the Free Software Foundation; either version 2 of the License, or (at
15.\" your option) any later version.
16.\"
17.\" mLib is distributed in the hope that it will be useful, but WITHOUT
18.\" ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
20.\" License for more details.
21.\"
22.\" You should have received a copy of the GNU Library General Public
23.\" License along with mLib. If not, write to the Free Software
24.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25.\" USA.
26.
27.\"--------------------------------------------------------------------------
28.so ../defs.man \" @@@PRE@@@
29.
30.\"--------------------------------------------------------------------------
31.TH tv 3mLib "22 May 1999" "Straylight/Edgeware" "mLib utilities library"
08da152e 32.\" @tv_add
33.\" @tv_addl
34.\" @tv_sub
35.\" @tv_subl
36.\" @tv_cmp
c4ccbbf9 37.
08da152e 38.\" @TV_ADD
39.\" @TV_ADDL
40.\" @TV_SUB
41.\" @TV_SUBL
42.\" @TV_CMP
c4ccbbf9
MW
43.
44.\"--------------------------------------------------------------------------
45.SH NAME
46tv \- arithmetic on \fBstruct timeval\fR objects
47.
48.\"--------------------------------------------------------------------------
b6b9d458 49.SH SYNOPSIS
c4ccbbf9 50.
b6b9d458 51.nf
52.B "#include <mLib/tv.h>"
d056fbdf 53.PP
b6b9d458 54.BI "void tv_add(struct timeval *" dst ,
55.BI " const struct timeval *" a ,
56.BI " const struct timeval *" b );
57.BI "void tv_addl(struct timeval *" dst ,
58.BI " const struct timeval *" a ,
59.BI " time_t " sec ", unsigned long " usec );
60.BI "void tv_sub(struct timeval *" dst ,
61.BI " const struct timeval *" a ,
62.BI " const struct timeval *" b );
63.BI "void tv_subl(struct timeval *" dst ,
64.BI " const struct timeval *" a ,
65.BI " time_t " sec ", unsigned long " usec );
66.BI "int tv_cmp(const struct timeval *" a ,
67.BI " const struct timeval *" b );
d056fbdf 68.PP
b6b9d458 69.B "int MILLION;"
70.BI "void TV_ADD(struct timeval *" dst ,
71.BI " const struct timeval *" a ,
72.BI " const struct timeval *" b );
73.BI "void TV_ADDL(struct timeval *" dst ,
74.BI " const struct timeval *" a ,
75.BI " time_t " sec ", unsigned long " usec );
76.BI "void TV_SUB(struct timeval *" dst ,
77.BI " const struct timeval *" a ,
78.BI " const struct timeval *" b );
79.BI "void TV_SUBL(struct timeval *" dst ,
80.BI " const struct timeval *" a ,
81.BI " time_t " sec ", unsigned long " usec );
82.BI "int TV_CMP(const struct timeval *" a ", " op ,
83.BI " const struct timeval *" b );
84.fi
c4ccbbf9
MW
85.
86.\"--------------------------------------------------------------------------
b6b9d458 87.SH DESCRIPTION
c4ccbbf9 88.
b6b9d458 89The
90.B <mLib/tv.h>
91header file provides functions and macros which perform simple
92arithmetic on objects of type
93.BR "struct timeval" ,
94which is capable of representing times to microsecond precision.
95See your
96.BR gettimeofday (2)
97or
98.BR select (2)
99manpages for details of this structure.
100.PP
101The macros are the recommended interface to
102.BR tv 's
103facilities. The function interface is provided for compatibility
104reasons, and for bizarre cases when macros won't do the job.
105.PP
106The main arithmetic functions are in three-address form: they accept two
107source arguments and a separate destination argument (which may be the
108same as one or even both of the source arguments). The destination is
109written before the sources. All the arguments are pointers to the
110actual structures.
111.PP
112.BI TV_ADD( d ", " x ", " y )
113adds
114.BR timeval s
115.I x
116and
117.I y
118storing the result in
119.IR d .
120Similarly,
121.BI TV_SUB( d ", " x ", " y )
122subtracts
123.I y
124from
125.I x
126storing the result in
127.IR d .
128.PP
129The macros
130.B TV_ADDL
131and
132.B TV_SUBL
133work the same way as
134.B TV_ADD
135and
136.B TV_SUB
137respectively, except their second source operand is expressed
138immediately as two integers arguments expressing a time in seconds and
139microseconds respectively. Hence,
140.BI TV_ADDL( d ", " s ", 3, 250000)"
141adds 3.25 seconds to
142.I s
143and puts the result in
144.IR d .
145Similarly,
146.BI TV_SUBL( d ", " s ", 3, 250000)"
147subtracts 3.25 seconds from
148.I s
149and puts the answer in
150.IR d .
151.PP
152The function equivalents for the above arithmetic macros work in exactly
153the same way (and indeed have trivial implementations in terms of the
154macros). The name of the function corresponding to a macro is simply
155the macro name in lower-case.
156.PP
157Two
158.B timeval
159objects can be compared using the
160.B TV_CMP
161macro. If
162.I op
163is a relational operator (e.g.,
164.RB ` == ',
165.RB ` < ',
166or
167.RB ` >= ')
168then
169.BI TV_CMP( x ", " op ", " y )
170is one when
171.I "x op y"
172is true and zero otherwise.
173.PP
174The function
175.B tv_cmp
176works differently. Given two arguments
177.I x
178and
179.IR y ,
180it returns -1 if
c4ccbbf9 181.IR x "\ <\ " y ,
b6b9d458 182zero if
c4ccbbf9 183.IR x "\ =\ " y ,
b6b9d458 184or 1 if
c4ccbbf9 185.IR x "\ >\ " y .
b6b9d458 186Hence, the result can be compared against zero in a relatively intuitive
187way (as for
188.BR strcmp (3),
189except that because the results are defined more tightly, it's possible
190to use a
191.B switch
192on the result).
193.SH ACKNOWLEDGEMENT
194The idea of passing a relational operator to
195.B TV_CMP
196is stolen from the
197.B timercmp
ff76c38f 198macro in the GNU C library. This doesn't look like a GNU original,
199however; whatever, it doesn't seem to be very portable. The GNU
b6b9d458 200.B timercmp
201macro had a warning attached to it that it wouldn't work for operators
202like
203.RB ` <= ',
204although I can't see why there'd be a problem. (If there is one, then
205my implementation has it too, because they're the same. I don't
206document the restriction because I don't think it exists.)
c4ccbbf9
MW
207.
208.\"--------------------------------------------------------------------------
08da152e 209.SH "SEE ALSO"
c4ccbbf9 210.
08da152e 211.BR mLib (3).
c4ccbbf9
MW
212.
213.\"--------------------------------------------------------------------------
b6b9d458 214.SH AUTHOR
c4ccbbf9 215.
9b5ac6ff 216Mark Wooding, <mdw@distorted.org.uk>
c4ccbbf9
MW
217.
218.\"----- That's all, folks --------------------------------------------------