xref: /openbsd-src/sbin/unwind/libunbound/util/timeval_func.h (revision d500c338f73eadbc8ea62778504d2ca76933e0f6)
1*d500c338Sflorian /*
2*d500c338Sflorian  * util/timeval_func.h - definitions of helpers for struct timeval values.
3*d500c338Sflorian  *
4*d500c338Sflorian  * Copyright (c) 2023, NLnet Labs. All rights reserved.
5*d500c338Sflorian  *
6*d500c338Sflorian  * This software is open source.
7*d500c338Sflorian  *
8*d500c338Sflorian  * Redistribution and use in source and binary forms, with or without
9*d500c338Sflorian  * modification, are permitted provided that the following conditions
10*d500c338Sflorian  * are met:
11*d500c338Sflorian  *
12*d500c338Sflorian  * Redistributions of source code must retain the above copyright notice,
13*d500c338Sflorian  * this list of conditions and the following disclaimer.
14*d500c338Sflorian  *
15*d500c338Sflorian  * Redistributions in binary form must reproduce the above copyright notice,
16*d500c338Sflorian  * this list of conditions and the following disclaimer in the documentation
17*d500c338Sflorian  * and/or other materials provided with the distribution.
18*d500c338Sflorian  *
19*d500c338Sflorian  * Neither the name of the NLNET LABS nor the names of its contributors may
20*d500c338Sflorian  * be used to endorse or promote products derived from this software without
21*d500c338Sflorian  * specific prior written permission.
22*d500c338Sflorian  *
23*d500c338Sflorian  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*d500c338Sflorian  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25*d500c338Sflorian  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26*d500c338Sflorian  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27*d500c338Sflorian  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28*d500c338Sflorian  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29*d500c338Sflorian  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30*d500c338Sflorian  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31*d500c338Sflorian  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32*d500c338Sflorian  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*d500c338Sflorian  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*d500c338Sflorian  */
35*d500c338Sflorian 
36*d500c338Sflorian /**
37*d500c338Sflorian  * \file
38*d500c338Sflorian  *
39*d500c338Sflorian  * This file contains definitions of helpers to manipulate struct timeval
40*d500c338Sflorian  * values, implemented in the corresponding C file.
41*d500c338Sflorian  */
42*d500c338Sflorian #include <sys/time.h>
43*d500c338Sflorian 
44*d500c338Sflorian #ifndef timeval_isset
45*d500c338Sflorian #define timeval_isset(tv) ((tv)->tv_sec || (tv)->tv_usec)
46*d500c338Sflorian #endif
47*d500c338Sflorian #ifndef timeval_clear
48*d500c338Sflorian #define timeval_clear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0)
49*d500c338Sflorian #endif
50*d500c338Sflorian void timeval_subtract(struct timeval* d, const struct timeval* end, const struct timeval* start);
51*d500c338Sflorian void timeval_add(struct timeval* d, const struct timeval* add);
52*d500c338Sflorian void timeval_divide(struct timeval* avg, const struct timeval* sum, long long d);
53*d500c338Sflorian int timeval_smaller(const struct timeval* x, const struct timeval* y);
54