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