3 * $Id: tv.c,v 1.6 2004/04/08 01:36:13 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 /*----- Header files ------------------------------------------------------*/
35 /*----- Main code ---------------------------------------------------------*/
39 * Arguments: @struct timeval *dst@ = destination block
40 * @const struct timeval *a, *b@ = source blocks
44 * Use: Adds two timevals.
47 void tv_add(struct timeval *dst,
48 const struct timeval *a, const struct timeval *b)
53 /* --- @tv_addl@ --- *
55 * Arguments: @struct timeval *dst@ = destination block
56 * @const struct timeval *a@ = source blocks
57 * @time_t sec@, @unsigned long usec@ = time to add
61 * Use: Adds a literal time in seconds and microseconds.
64 void tv_addl(struct timeval *dst, const struct timeval *a,
65 time_t sec, unsigned long usec)
67 TV_ADDL(dst, a, sec, usec);
72 * Arguments: @struct timeval *dst@ = destination block
73 * @const struct timeval *a, *b@ = source blocks
77 * Use: Subtracts two timevals.
80 void tv_sub(struct timeval *dst,
81 const struct timeval *a, const struct timeval *b)
86 /* --- @tv_subl@ --- *
88 * Arguments: @struct timeval *dst@ = destination block
89 * @const struct timeval *a@ = source blocks
90 * @time_t sec@, @unsigned long usec@ = time to subtract
94 * Use: Subtracts a literal time in seconds and microseconds.
97 void tv_subl(struct timeval *dst, const struct timeval *a,
98 time_t sec, unsigned long usec)
100 TV_SUBL(dst, a, sec, usec);
103 /* --- @tv_cmp@ --- *
105 * Arguments: @const struct timeval *a, *b@ = source blocks
107 * Returns: Less than, equal to, or greater than zero.
109 * Use: Compares two timevals.
112 int tv_cmp(const struct timeval *a, const struct timeval *b)
114 /* --- This is more awkward than the case the macro deals with --- */
116 if (a->tv_sec > b->tv_sec)
118 else if (a->tv_sec < b->tv_sec)
120 else if (a->tv_usec > b->tv_usec)
122 else if (a->tv_usec < b->tv_usec)
128 /*----- That's all, folks -------------------------------------------------*/