3 * $Id: tv.c,v 1.1 1998/11/25 23:30:01 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 General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (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 General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with mLib; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.1 1998/11/25 23:30:01 mdw
37 /*----- Header files ------------------------------------------------------*/
42 /*----- Main code ---------------------------------------------------------*/
46 * Arguments: @struct timeval *dst@ = destination block
47 * @const struct timeval *a, *b@ = source blocks
51 * Use: Adds two timevals.
54 void tv_add(struct timeval
*dst
,
55 const struct timeval
*a
, const struct timeval
*b
)
57 dst
->tv_sec
= a
->tv_sec
+ b
->tv_sec
;
58 dst
->tv_usec
= a
->tv_usec
+ b
->tv_usec
;
59 if (dst
->tv_usec
>= 1000000) {
60 dst
->tv_usec
-= 1000000;
67 * Arguments: @struct timeval *dst@ = destination block
68 * @const struct timeval *a, *b@ = source blocks
72 * Use: Subtracts two timevals.
75 void tv_sub(struct timeval
*dst
,
76 const struct timeval
*a
, const struct timeval
*b
)
78 dst
->tv_sec
= a
->tv_sec
- b
->tv_sec
;
79 if (a
->tv_usec
>= b
->tv_usec
)
80 dst
->tv_usec
= a
->tv_usec
- b
->tv_usec
;
82 dst
->tv_usec
= a
->tv_usec
+ 1000000 - b
->tv_usec
;
89 * Arguments: @const struct timeval *a, *b@ = source blocks
91 * Returns: Less than, equal to, or greater than zero.
93 * Use: Compares two timevals.
96 int tv_cmp(const struct timeval
*a
, const struct timeval
*b
)
98 if (a
->tv_sec
> b
->tv_sec
)
100 else if (a
->tv_sec
< b
->tv_sec
)
102 else if (a
->tv_usec
> b
->tv_usec
)
104 else if (a
->tv_usec
< b
->tv_usec
)
110 /*----- That's all, folks -------------------------------------------------*/