3 * $Id: tv.h,v 1.5 1999/05/21 22:13:12 mdw Exp $
5 * Manipulation of timeval structures
7 * (c) 1998 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.5 1999/05/21 22:13:12 mdw
34 * Moved most of the code into exported macros. The main functions now
35 * implemented using the macros.
37 * Revision 1.4 1999/05/17 20:37:25 mdw
38 * New function `tv_addl' to add a literal to a time value.
40 * Revision 1.3 1999/05/06 19:51:36 mdw
41 * Reformatted the LGPL notice a little bit.
43 * Revision 1.2 1999/05/05 18:50:31 mdw
44 * Change licensing conditions to LGPL.
46 * Revision 1.1 1998/11/25 23:30:01 mdw
58 /*----- Header files ------------------------------------------------------*/
62 /*----- A macro to make reading easier ------------------------------------*/
64 #define MILLION 1000000
66 /*----- Functions provided ------------------------------------------------*/
70 * Arguments: @struct timeval *dst@ = destination block
71 * @const struct timeval *a, *b@ = source blocks
75 * Use: Adds two timevals.
78 extern void tv_add(struct timeval */
*dst*/
,
79 const struct timeval */
*a*/
,
80 const struct timeval */
*b*/
);
82 #define TV_ADD(dst, a, b) TV_ADDL(dst, a, (b)->tv_sec, (b)->tv_usec)
84 /* --- @tv_addl@ --- *
86 * Arguments: @struct timeval *dst@ = destination block
87 * @const struct timeval *a@ = source blocks
88 * @time_t sec@, @unsigned long usec@ = time to add
92 * Use: Adds a literal time in seconds and microseconds.
95 extern void tv_addl(struct timeval */
*dst*/
,
96 const struct timeval */
*a*/
,
97 time_t /*sec*/, unsigned long /*usec*/);
99 #define TV_ADDL(dst, a, sec, usec) do { \
100 (dst)->tv_sec = (a)->tv_sec + (sec); \
101 (dst)->tv_usec = (a)->tv_usec + (usec); \
102 if ((dst)->tv_usec >= MILLION) { \
103 (dst)->tv_usec -= MILLION; \
108 /* --- @tv_sub@ --- *
110 * Arguments: @struct timeval *dst@ = destination block
111 * @const struct timeval *a, *b@ = source blocks
115 * Use: Subtracts two timevals.
118 extern void tv_sub(struct timeval */
*dst*/
,
119 const struct timeval */
*a*/
,
120 const struct timeval */
*b*/
);
122 #define TV_SUB(dst, a, b) TV_SUBL(dst, a, (b)->tv_sec, (b)->tv_usec)
124 /* --- @tv_subl@ --- *
126 * Arguments: @struct timeval *dst@ = destination block
127 * @const struct timeval *a@ = source blocks
128 * @time_t sec@, @unsigned long usec@ = time to subtract
132 * Use: Subtracts a literal time in seconds and microseconds.
135 extern void tv_subl(struct timeval */
*dst*/
,
136 const struct timeval */
*a*/
,
137 time_t /*sec*/, unsigned long /*usec*/);
139 #define TV_SUBL(dst, a, sec, usec) do { \
140 (dst)->tv_sec = (a)->tv_sec - (sec); \
141 if ((a)->tv_usec >= (usec)) \
142 (dst)->tv_usec = (a)->tv_usec - (usec); \
144 (dst)->tv_usec = (a)->tv_usec + MILLION - (usec); \
149 /* --- @tv_cmp@ --- *
151 * Arguments: @const struct timeval *a, *b@ = source blocks
153 * Returns: Less than, equal to, or greater than zero.
155 * Use: Compares two timevals.
158 extern int tv_cmp(const struct timeval */
*a*/
,
159 const struct timeval */
*b*/
);
161 #define TV_CMP(a, op, b) ((a)->tv_sec == (b)->tv_sec ? \
162 (a)->tv_usec op (b)->tv_usec : \
163 (a)->tv_sec op (b)->tv_sec)
165 /*----- That's all, folks -------------------------------------------------*/