chiark / gitweb /
Infrastructure: Switch testing over to Autotest.
[mLib] / sys / tv.c
CommitLineData
247239be 1/* -*-c-*-
247239be 2 *
3 * Manipulation of timeval structures
4 *
5 * (c) 1998 Straylight/Edgeware
6 */
7
d4efbcd9 8/*----- Licensing notice --------------------------------------------------*
247239be 9 *
10 * This file is part of the mLib utilities library.
11 *
12 * mLib is free software; you can redistribute it and/or modify
c846879c 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.
d4efbcd9 16 *
247239be 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
c846879c 20 * GNU Library General Public License for more details.
d4efbcd9 21 *
c846879c 22 * You should have received a copy of the GNU Library General Public
0bd98442 23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 * MA 02111-1307, USA.
247239be 26 */
27
247239be 28/*----- Header files ------------------------------------------------------*/
29
30#include <sys/time.h>
31#include "tv.h"
32
33/*----- Main code ---------------------------------------------------------*/
34
35/* --- @tv_add@ --- *
36 *
37 * Arguments: @struct timeval *dst@ = destination block
38 * @const struct timeval *a, *b@ = source blocks
39 *
40 * Returns: ---
41 *
42 * Use: Adds two timevals.
43 */
44
45void tv_add(struct timeval *dst,
46 const struct timeval *a, const struct timeval *b)
47{
9239a724 48 TV_ADD(dst, a, b);
88bd7f65 49}
50
51/* --- @tv_addl@ --- *
52 *
53 * Arguments: @struct timeval *dst@ = destination block
54 * @const struct timeval *a@ = source blocks
55 * @time_t sec@, @unsigned long usec@ = time to add
56 *
57 * Returns: ---
58 *
59 * Use: Adds a literal time in seconds and microseconds.
60 */
61
62void tv_addl(struct timeval *dst, const struct timeval *a,
63 time_t sec, unsigned long usec)
64{
9239a724 65 TV_ADDL(dst, a, sec, usec);
247239be 66}
67
68/* --- @tv_sub@ --- *
69 *
70 * Arguments: @struct timeval *dst@ = destination block
71 * @const struct timeval *a, *b@ = source blocks
72 *
73 * Returns: ---
74 *
75 * Use: Subtracts two timevals.
76 */
77
78void tv_sub(struct timeval *dst,
79 const struct timeval *a, const struct timeval *b)
80{
9239a724 81 TV_SUB(dst, a, b);
82}
83
84/* --- @tv_subl@ --- *
85 *
86 * Arguments: @struct timeval *dst@ = destination block
87 * @const struct timeval *a@ = source blocks
88 * @time_t sec@, @unsigned long usec@ = time to subtract
89 *
90 * Returns: ---
91 *
92 * Use: Subtracts a literal time in seconds and microseconds.
93 */
94
95void tv_subl(struct timeval *dst, const struct timeval *a,
96 time_t sec, unsigned long usec)
97{
98 TV_SUBL(dst, a, sec, usec);
247239be 99}
100
101/* --- @tv_cmp@ --- *
102 *
103 * Arguments: @const struct timeval *a, *b@ = source blocks
104 *
105 * Returns: Less than, equal to, or greater than zero.
106 *
107 * Use: Compares two timevals.
108 */
109
110int tv_cmp(const struct timeval *a, const struct timeval *b)
111{
9239a724 112 /* --- This is more awkward than the case the macro deals with --- */
113
247239be 114 if (a->tv_sec > b->tv_sec)
115 return (1);
116 else if (a->tv_sec < b->tv_sec)
117 return (-1);
118 else if (a->tv_usec > b->tv_usec)
119 return (1);
120 else if (a->tv_usec < b->tv_usec)
121 return (-1);
122 else
123 return (0);
124}
125
126/*----- That's all, folks -------------------------------------------------*/