chiark / gitweb /
Headers: Guard inclusion of mLib headers.
[mLib] / tv.c
diff --git a/tv.c b/tv.c
index eeeb8b0d660dbcfb04ef77d02e20bee787b57269..dca58cc2cf6e8bfa48ab6868abc1ab97c092f4bc 100644 (file)
--- a/tv.c
+++ b/tv.c
@@ -1,13 +1,11 @@
 /* -*-c-*-
- *
- * $Id: tv.c,v 1.4 1999/05/17 20:37:52 mdw Exp $
  *
  * Manipulation of timeval structures
  *
  * (c) 1998 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * 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 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.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.
- *
- * 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.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <sys/time.h>
 #include "tv.h"
 
-/*----- A macro to make reading easier ------------------------------------*/
-
-#define MILLION 1000000
-
 /*----- Main code ---------------------------------------------------------*/
 
 /* --- @tv_add@ --- *
 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 >= MILLION) {
-    dst->tv_usec -= MILLION;
-    dst->tv_sec++;
-  }
+  TV_ADD(dst, a, b);
 }
 
 /* --- @tv_addl@ --- *
@@ -91,12 +62,7 @@ void tv_add(struct timeval *dst,
 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++;
-  }
+  TV_ADDL(dst, a, sec, usec);
 }
 
 /* --- @tv_sub@ --- *
@@ -112,13 +78,24 @@ void tv_addl(struct timeval *dst, const struct timeval *a,
 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 + MILLION - 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@ --- *
@@ -132,6 +109,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)