From 88bd7f658d494cd5aae62972e39294c2e01c2da3 Mon Sep 17 00:00:00 2001 Message-Id: <88bd7f658d494cd5aae62972e39294c2e01c2da3.1715584367.git.mdw@distorted.org.uk> From: Mark Wooding Date: Mon, 17 May 1999 20:37:52 +0000 Subject: [PATCH] New function `tv_addl' to add a literal to a time value. Use magical `MILLION' constant in place of 1000000 for ease of reading. Organization: Straylight/Edgeware From: mdw --- tv.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/tv.c b/tv.c index b01a048..eeeb8b0 100644 --- a/tv.c +++ b/tv.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tv.c,v 1.3 1999/05/06 19:51:36 mdw Exp $ + * $Id: tv.c,v 1.4 1999/05/17 20:37:52 mdw Exp $ * * Manipulation of timeval structures * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: tv.c,v $ + * Revision 1.4 1999/05/17 20:37:52 mdw + * New function `tv_addl' to add a literal to a time value. Use magical + * `MILLION' constant in place of 1000000 for ease of reading. + * * Revision 1.3 1999/05/06 19:51:36 mdw * Reformatted the LGPL notice a little bit. * @@ -46,6 +50,10 @@ #include #include "tv.h" +/*----- A macro to make reading easier ------------------------------------*/ + +#define MILLION 1000000 + /*----- Main code ---------------------------------------------------------*/ /* --- @tv_add@ --- * @@ -63,8 +71,30 @@ void tv_add(struct timeval *dst, { 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; + if (dst->tv_usec >= MILLION) { + dst->tv_usec -= MILLION; + dst->tv_sec++; + } +} + +/* --- @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) +{ + dst->tv_sec = a->tv_sec + sec; + dst->tv_usec = a->tv_usec + usec; + if (dst->tv_usec >= MILLION) { + dst->tv_usec -= MILLION; dst->tv_sec++; } } @@ -86,7 +116,7 @@ void tv_sub(struct timeval *dst, 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_usec = a->tv_usec + MILLION - b->tv_usec; dst->tv_sec--; } } -- [mdw]