X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/c846879ccf3e86ea293c157f4aa2ff8716fb5b4c..5ce3df295ef9bc476620d9a19271239aff40214c:/tv.c diff --git a/tv.c b/tv.c index 1596e6e..618930c 100644 --- a/tv.c +++ b/tv.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tv.c,v 1.2 1999/05/05 18:50:31 mdw Exp $ + * $Id: tv.c,v 1.6 2004/04/08 01:36:13 mdw Exp $ * * Manipulation of timeval structures * @@ -22,19 +22,9 @@ * GNU Library General Public License for more details. * * 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. - */ - -/*----- Revision history --------------------------------------------------* - * - * $Log: tv.c,v $ - * Revision 1.2 1999/05/05 18:50:31 mdw - * Change licensing conditions to LGPL. - * - * Revision 1.1 1998/11/25 23:30:01 mdw - * New file. - * + * 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 ------------------------------------------------------*/ @@ -57,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@ --- * @@ -78,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@ --- * @@ -98,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)