chiark / gitweb /
New function `tv_addl' to add a literal to a time value. Use magical 1.3.1
authormdw <mdw>
Mon, 17 May 1999 20:37:52 +0000 (20:37 +0000)
committermdw <mdw>
Mon, 17 May 1999 20:37:52 +0000 (20:37 +0000)
`MILLION' constant in place of 1000000 for ease of reading.

tv.c

diff --git a/tv.c b/tv.c
index b01a048d538960b0c21d9726cfb2fc2c3210d1af..eeeb8b0d660dbcfb04ef77d02e20bee787b57269 100644 (file)
--- 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
  *
 /*----- 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.
  *
 #include <sys/time.h>
 #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--;
   }
 }