3 * $Id: tv.h,v 1.6 1999/12/10 23:42:04 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.6 1999/12/10 23:42:04 mdw
34 * Change header file guard names.
36 * Revision 1.5 1999/05/21 22:13:12 mdw
37 * Moved most of the code into exported macros. The main functions now
38 * implemented using the macros.
40 * Revision 1.4 1999/05/17 20:37:25 mdw
41 * New function `tv_addl' to add a literal to a time value.
43 * Revision 1.3 1999/05/06 19:51:36 mdw
44 * Reformatted the LGPL notice a little bit.
46 * Revision 1.2 1999/05/05 18:50:31 mdw
47 * Change licensing conditions to LGPL.
49 * Revision 1.1 1998/11/25 23:30:01 mdw
61 /*----- Header files ------------------------------------------------------*/
65 /*----- A macro to make reading easier ------------------------------------*/
67 #define MILLION 1000000
69 /*----- Functions provided ------------------------------------------------*/
73 * Arguments: @struct timeval *dst@ = destination block
74 * @const struct timeval *a, *b@ = source blocks
78 * Use: Adds two timevals.
81 extern void tv_add(struct timeval */
*dst*/
,
82 const struct timeval */
*a*/
,
83 const struct timeval */
*b*/
);
85 #define TV_ADD(dst, a, b) TV_ADDL(dst, a, (b)->tv_sec, (b)->tv_usec)
87 /* --- @tv_addl@ --- *
89 * Arguments: @struct timeval *dst@ = destination block
90 * @const struct timeval *a@ = source blocks
91 * @time_t sec@, @unsigned long usec@ = time to add
95 * Use: Adds a literal time in seconds and microseconds.
98 extern void tv_addl(struct timeval */
*dst*/
,
99 const struct timeval */
*a*/
,
100 time_t /*sec*/, unsigned long /*usec*/);
102 #define TV_ADDL(dst, a, sec, usec) do { \
103 (dst)->tv_sec = (a)->tv_sec + (sec); \
104 (dst)->tv_usec = (a)->tv_usec + (usec); \
105 if ((dst)->tv_usec >= MILLION) { \
106 (dst)->tv_usec -= MILLION; \
111 /* --- @tv_sub@ --- *
113 * Arguments: @struct timeval *dst@ = destination block
114 * @const struct timeval *a, *b@ = source blocks
118 * Use: Subtracts two timevals.
121 extern void tv_sub(struct timeval */
*dst*/
,
122 const struct timeval */
*a*/
,
123 const struct timeval */
*b*/
);
125 #define TV_SUB(dst, a, b) TV_SUBL(dst, a, (b)->tv_sec, (b)->tv_usec)
127 /* --- @tv_subl@ --- *
129 * Arguments: @struct timeval *dst@ = destination block
130 * @const struct timeval *a@ = source blocks
131 * @time_t sec@, @unsigned long usec@ = time to subtract
135 * Use: Subtracts a literal time in seconds and microseconds.
138 extern void tv_subl(struct timeval */
*dst*/
,
139 const struct timeval */
*a*/
,
140 time_t /*sec*/, unsigned long /*usec*/);
142 #define TV_SUBL(dst, a, sec, usec) do { \
143 (dst)->tv_sec = (a)->tv_sec - (sec); \
144 if ((a)->tv_usec >= (usec)) \
145 (dst)->tv_usec = (a)->tv_usec - (usec); \
147 (dst)->tv_usec = (a)->tv_usec + MILLION - (usec); \
152 /* --- @tv_cmp@ --- *
154 * Arguments: @const struct timeval *a, *b@ = source blocks
156 * Returns: Less than, equal to, or greater than zero.
158 * Use: Compares two timevals.
161 extern int tv_cmp(const struct timeval */
*a*/
,
162 const struct timeval */
*b*/
);
164 #define TV_CMP(a, op, b) ((a)->tv_sec == (b)->tv_sec ? \
165 (a)->tv_usec op (b)->tv_usec : \
166 (a)->tv_sec op (b)->tv_sec)
168 /*----- That's all, folks -------------------------------------------------*/