2 .TH tv 3 "22 May 1999" "Straylight/Edgeware" "mLib utilities library"
4 tv \- arithmetic on \fBstruct timeval\fR objects
19 .B "#include <mLib/tv.h>"
21 .BI "void tv_add(struct timeval *" dst ,
22 .BI " const struct timeval *" a ,
23 .BI " const struct timeval *" b );
24 .BI "void tv_addl(struct timeval *" dst ,
25 .BI " const struct timeval *" a ,
26 .BI " time_t " sec ", unsigned long " usec );
27 .BI "void tv_sub(struct timeval *" dst ,
28 .BI " const struct timeval *" a ,
29 .BI " const struct timeval *" b );
30 .BI "void tv_subl(struct timeval *" dst ,
31 .BI " const struct timeval *" a ,
32 .BI " time_t " sec ", unsigned long " usec );
33 .BI "int tv_cmp(const struct timeval *" a ,
34 .BI " const struct timeval *" b );
37 .BI "void TV_ADD(struct timeval *" dst ,
38 .BI " const struct timeval *" a ,
39 .BI " const struct timeval *" b );
40 .BI "void TV_ADDL(struct timeval *" dst ,
41 .BI " const struct timeval *" a ,
42 .BI " time_t " sec ", unsigned long " usec );
43 .BI "void TV_SUB(struct timeval *" dst ,
44 .BI " const struct timeval *" a ,
45 .BI " const struct timeval *" b );
46 .BI "void TV_SUBL(struct timeval *" dst ,
47 .BI " const struct timeval *" a ,
48 .BI " time_t " sec ", unsigned long " usec );
49 .BI "int TV_CMP(const struct timeval *" a ", " op ,
50 .BI " const struct timeval *" b );
55 header file provides functions and macros which perform simple
56 arithmetic on objects of type
57 .BR "struct timeval" ,
58 which is capable of representing times to microsecond precision.
63 manpages for details of this structure.
65 The macros are the recommended interface to
67 facilities. The function interface is provided for compatibility
68 reasons, and for bizarre cases when macros won't do the job.
70 The main arithmetic functions are in three-address form: they accept two
71 source arguments and a separate destination argument (which may be the
72 same as one or even both of the source arguments). The destination is
73 written before the sources. All the arguments are pointers to the
76 .BI TV_ADD( d ", " x ", " y )
85 .BI TV_SUB( d ", " x ", " y )
101 respectively, except their second source operand is expressed
102 immediately as two integers arguments expressing a time in seconds and
103 microseconds respectively. Hence,
104 .BI TV_ADDL( d ", " s ", 3, 250000)"
107 and puts the result in
110 .BI TV_SUBL( d ", " s ", 3, 250000)"
111 subtracts 3.25 seconds from
113 and puts the answer in
116 The function equivalents for the above arithmetic macros work in exactly
117 the same way (and indeed have trivial implementations in terms of the
118 macros). The name of the function corresponding to a macro is simply
119 the macro name in lower-case.
123 objects can be compared using the
127 is a relational operator (e.g.,
133 .BI TV_CMP( x ", " op ", " y )
136 is true and zero otherwise.
140 works differently. Given two arguments
150 Hence, the result can be compared against zero in a relatively intuitive
153 except that because the results are defined more tightly, it's possible
158 The idea of passing a relational operator to
162 macro in the GNU C library. This doesn't look like a GNU original,
163 however; whatever, it doesn't seem to be very portable. The GNU
165 macro had a warning attached to it that it wouldn't work for operators
168 although I can't see why there'd be a problem. (If there is one, then
169 my implementation has it too, because they're the same. I don't
170 document the restriction because I don't think it exists.)
174 Mark Wooding, <mdw@distorted.org.uk>