15e9cd1aeSAssar Westerlund /*
25e9cd1aeSAssar Westerlund * Copyright (c) 1999 Kungliga Tekniska Högskolan
35e9cd1aeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden).
45e9cd1aeSAssar Westerlund * All rights reserved.
55e9cd1aeSAssar Westerlund *
65e9cd1aeSAssar Westerlund * Redistribution and use in source and binary forms, with or without
75e9cd1aeSAssar Westerlund * modification, are permitted provided that the following conditions
85e9cd1aeSAssar Westerlund * are met:
95e9cd1aeSAssar Westerlund *
105e9cd1aeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright
115e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer.
125e9cd1aeSAssar Westerlund *
135e9cd1aeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright
145e9cd1aeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the
155e9cd1aeSAssar Westerlund * documentation and/or other materials provided with the distribution.
165e9cd1aeSAssar Westerlund *
175e9cd1aeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors
185e9cd1aeSAssar Westerlund * may be used to endorse or promote products derived from this software
195e9cd1aeSAssar Westerlund * without specific prior written permission.
205e9cd1aeSAssar Westerlund *
215e9cd1aeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
225e9cd1aeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
235e9cd1aeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
245e9cd1aeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
255e9cd1aeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
265e9cd1aeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
275e9cd1aeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
285e9cd1aeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
295e9cd1aeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
305e9cd1aeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
315e9cd1aeSAssar Westerlund * SUCH DAMAGE.
325e9cd1aeSAssar Westerlund */
335e9cd1aeSAssar Westerlund
345e9cd1aeSAssar Westerlund /*
355e9cd1aeSAssar Westerlund * Timeval stuff
365e9cd1aeSAssar Westerlund */
375e9cd1aeSAssar Westerlund
385e9cd1aeSAssar Westerlund #include <config.h>
395e9cd1aeSAssar Westerlund
40c19800e8SDoug Rabson #include "roken.h"
415e9cd1aeSAssar Westerlund
425e9cd1aeSAssar Westerlund /*
435e9cd1aeSAssar Westerlund * Make `t1' consistent.
445e9cd1aeSAssar Westerlund */
455e9cd1aeSAssar Westerlund
465e9cd1aeSAssar Westerlund ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
timevalfix(struct timeval * t1)475e9cd1aeSAssar Westerlund timevalfix(struct timeval *t1)
485e9cd1aeSAssar Westerlund {
49c19800e8SDoug Rabson if (t1->tv_usec < 0) {
505e9cd1aeSAssar Westerlund t1->tv_sec--;
515e9cd1aeSAssar Westerlund t1->tv_usec += 1000000;
525e9cd1aeSAssar Westerlund }
535e9cd1aeSAssar Westerlund if (t1->tv_usec >= 1000000) {
545e9cd1aeSAssar Westerlund t1->tv_sec++;
555e9cd1aeSAssar Westerlund t1->tv_usec -= 1000000;
565e9cd1aeSAssar Westerlund }
575e9cd1aeSAssar Westerlund }
585e9cd1aeSAssar Westerlund
595e9cd1aeSAssar Westerlund /*
605e9cd1aeSAssar Westerlund * t1 += t2
615e9cd1aeSAssar Westerlund */
625e9cd1aeSAssar Westerlund
635e9cd1aeSAssar Westerlund ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
timevaladd(struct timeval * t1,const struct timeval * t2)645e9cd1aeSAssar Westerlund timevaladd(struct timeval *t1, const struct timeval *t2)
655e9cd1aeSAssar Westerlund {
66c19800e8SDoug Rabson t1->tv_sec += t2->tv_sec;
675e9cd1aeSAssar Westerlund t1->tv_usec += t2->tv_usec;
685e9cd1aeSAssar Westerlund timevalfix(t1);
695e9cd1aeSAssar Westerlund }
705e9cd1aeSAssar Westerlund
715e9cd1aeSAssar Westerlund /*
725e9cd1aeSAssar Westerlund * t1 -= t2
735e9cd1aeSAssar Westerlund */
745e9cd1aeSAssar Westerlund
755e9cd1aeSAssar Westerlund ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
timevalsub(struct timeval * t1,const struct timeval * t2)765e9cd1aeSAssar Westerlund timevalsub(struct timeval *t1, const struct timeval *t2)
775e9cd1aeSAssar Westerlund {
78c19800e8SDoug Rabson t1->tv_sec -= t2->tv_sec;
795e9cd1aeSAssar Westerlund t1->tv_usec -= t2->tv_usec;
805e9cd1aeSAssar Westerlund timevalfix(t1);
815e9cd1aeSAssar Westerlund }
825e9cd1aeSAssar Westerlund