X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/247239becbeb8f8f92d86e038de6315437679f71..9dc511e46d5acad665175981f824288062e27671:/tv.c diff --git a/tv.c b/tv.c index 9548a13..618930c 100644 --- a/tv.c +++ b/tv.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tv.c,v 1.1 1998/11/25 23:30:01 mdw Exp $ + * $Id: tv.c,v 1.6 2004/04/08 01:36:13 mdw Exp $ * * Manipulation of timeval structures * @@ -12,26 +12,19 @@ * This file is part of the mLib utilities library. * * mLib is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. * * mLib is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU Library General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with mLib; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/*----- Revision history --------------------------------------------------* - * - * $Log: tv.c,v $ - * Revision 1.1 1998/11/25 23:30:01 mdw - * New file. - * + * You should have received a copy of the GNU Library General Public + * License along with mLib; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ @@ -54,12 +47,24 @@ void tv_add(struct timeval *dst, const struct timeval *a, const struct timeval *b) { - dst->tv_sec = a->tv_sec + b->tv_sec; - dst->tv_usec = a->tv_usec + b->tv_usec; - if (dst->tv_usec >= 1000000) { - dst->tv_usec -= 1000000; - dst->tv_sec++; - } + TV_ADD(dst, a, b); +} + +/* --- @tv_addl@ --- * + * + * Arguments: @struct timeval *dst@ = destination block + * @const struct timeval *a@ = source blocks + * @time_t sec@, @unsigned long usec@ = time to add + * + * Returns: --- + * + * Use: Adds a literal time in seconds and microseconds. + */ + +void tv_addl(struct timeval *dst, const struct timeval *a, + time_t sec, unsigned long usec) +{ + TV_ADDL(dst, a, sec, usec); } /* --- @tv_sub@ --- * @@ -75,13 +80,24 @@ void tv_add(struct timeval *dst, void tv_sub(struct timeval *dst, const struct timeval *a, const struct timeval *b) { - dst->tv_sec = a->tv_sec - b->tv_sec; - if (a->tv_usec >= b->tv_usec) - dst->tv_usec = a->tv_usec - b->tv_usec; - else { - dst->tv_usec = a->tv_usec + 1000000 - b->tv_usec; - dst->tv_sec--; - } + TV_SUB(dst, a, b); +} + +/* --- @tv_subl@ --- * + * + * Arguments: @struct timeval *dst@ = destination block + * @const struct timeval *a@ = source blocks + * @time_t sec@, @unsigned long usec@ = time to subtract + * + * Returns: --- + * + * Use: Subtracts a literal time in seconds and microseconds. + */ + +void tv_subl(struct timeval *dst, const struct timeval *a, + time_t sec, unsigned long usec) +{ + TV_SUBL(dst, a, sec, usec); } /* --- @tv_cmp@ --- * @@ -95,6 +111,8 @@ void tv_sub(struct timeval *dst, int tv_cmp(const struct timeval *a, const struct timeval *b) { + /* --- This is more awkward than the case the macro deals with --- */ + if (a->tv_sec > b->tv_sec) return (1); else if (a->tv_sec < b->tv_sec)