3 * Manipulation of timeval structures
5 * (c) 1998 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
33 /*----- Main code ---------------------------------------------------------*/
37 * Arguments: @struct timeval *dst@ = destination block
38 * @const struct timeval *a, *b@ = source blocks
42 * Use: Adds two timevals.
45 void tv_add(struct timeval
*dst
,
46 const struct timeval
*a
, const struct timeval
*b
)
51 /* --- @tv_addl@ --- *
53 * Arguments: @struct timeval *dst@ = destination block
54 * @const struct timeval *a@ = source blocks
55 * @time_t sec@, @unsigned long usec@ = time to add
59 * Use: Adds a literal time in seconds and microseconds.
62 void tv_addl(struct timeval
*dst
, const struct timeval
*a
,
63 time_t sec
, unsigned long usec
)
65 TV_ADDL(dst
, a
, sec
, usec
);
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
)
84 /* --- @tv_subl@ --- *
86 * Arguments: @struct timeval *dst@ = destination block
87 * @const struct timeval *a@ = source blocks
88 * @time_t sec@, @unsigned long usec@ = time to subtract
92 * Use: Subtracts a literal time in seconds and microseconds.
95 void tv_subl(struct timeval
*dst
, const struct timeval
*a
,
96 time_t sec
, unsigned long usec
)
98 TV_SUBL(dst
, a
, sec
, usec
);
101 /* --- @tv_cmp@ --- *
103 * Arguments: @const struct timeval *a, *b@ = source blocks
105 * Returns: Less than, equal to, or greater than zero.
107 * Use: Compares two timevals.
110 int tv_cmp(const struct timeval
*a
, const struct timeval
*b
)
112 /* --- This is more awkward than the case the macro deals with --- */
114 if (a
->tv_sec
> b
->tv_sec
)
116 else if (a
->tv_sec
< b
->tv_sec
)
118 else if (a
->tv_usec
> b
->tv_usec
)
120 else if (a
->tv_usec
< b
->tv_usec
)
126 /*----- That's all, folks -------------------------------------------------*/