1596e6e5aabe2a44b69df35ea6a7dd42a3f93359
3 * $Id: tv.c,v 1.2 1999/05/05 18:50:31 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 Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1999/05/05 18:50:31 mdw
33 * Change licensing conditions to LGPL.
35 * Revision 1.1 1998/11/25 23:30:01 mdw
40 /*----- Header files ------------------------------------------------------*/
45 /*----- Main code ---------------------------------------------------------*/
49 * Arguments: @struct timeval *dst@ = destination block
50 * @const struct timeval *a, *b@ = source blocks
54 * Use: Adds two timevals.
57 void tv_add(struct timeval
*dst
,
58 const struct timeval
*a
, const struct timeval
*b
)
60 dst
->tv_sec
= a
->tv_sec
+ b
->tv_sec
;
61 dst
->tv_usec
= a
->tv_usec
+ b
->tv_usec
;
62 if (dst
->tv_usec
>= 1000000) {
63 dst
->tv_usec
-= 1000000;
70 * Arguments: @struct timeval *dst@ = destination block
71 * @const struct timeval *a, *b@ = source blocks
75 * Use: Subtracts two timevals.
78 void tv_sub(struct timeval
*dst
,
79 const struct timeval
*a
, const struct timeval
*b
)
81 dst
->tv_sec
= a
->tv_sec
- b
->tv_sec
;
82 if (a
->tv_usec
>= b
->tv_usec
)
83 dst
->tv_usec
= a
->tv_usec
- b
->tv_usec
;
85 dst
->tv_usec
= a
->tv_usec
+ 1000000 - b
->tv_usec
;
92 * Arguments: @const struct timeval *a, *b@ = source blocks
94 * Returns: Less than, equal to, or greater than zero.
96 * Use: Compares two timevals.
99 int tv_cmp(const struct timeval
*a
, const struct timeval
*b
)
101 if (a
->tv_sec
> b
->tv_sec
)
103 else if (a
->tv_sec
< b
->tv_sec
)
105 else if (a
->tv_usec
> b
->tv_usec
)
107 else if (a
->tv_usec
< b
->tv_usec
)
113 /*----- That's all, folks -------------------------------------------------*/