chiark / gitweb /
New file.
authormdw <mdw>
Wed, 25 Nov 1998 23:30:01 +0000 (23:30 +0000)
committermdw <mdw>
Wed, 25 Nov 1998 23:30:01 +0000 (23:30 +0000)
tv.c [new file with mode: 0644]
tv.h [new file with mode: 0644]

diff --git a/tv.c b/tv.c
new file mode 100644 (file)
index 0000000..9548a13
--- /dev/null
+++ b/tv.c
@@ -0,0 +1,110 @@
+/* -*-c-*-
+ *
+ * $Id: tv.c,v 1.1 1998/11/25 23:30:01 mdw Exp $
+ *
+ * Manipulation of timeval structures
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * 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.
+ * 
+ * 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.
+ * 
+ * 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.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <sys/time.h>
+#include "tv.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- @tv_add@ --- *
+ *
+ * Arguments:  @struct timeval *dst@ = destination block
+ *             @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds two timevals.
+ */
+
+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_sub@ --- *
+ *
+ * Arguments:  @struct timeval *dst@ = destination block
+ *             @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    ---
+ *
+ * Use:                Subtracts two timevals.
+ */
+
+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_cmp@ --- *
+ *
+ * Arguments:  @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    Less than, equal to, or greater than zero.
+ *
+ * Use:                Compares two timevals.
+ */
+
+int tv_cmp(const struct timeval *a, const struct timeval *b)
+{
+  if (a->tv_sec > b->tv_sec)
+    return (1);
+  else if (a->tv_sec < b->tv_sec)
+    return (-1);
+  else if (a->tv_usec > b->tv_usec)
+    return (1);
+  else if (a->tv_usec < b->tv_usec)
+    return (-1);
+  else
+    return (0);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
diff --git a/tv.h b/tv.h
new file mode 100644 (file)
index 0000000..99eb2d7
--- /dev/null
+++ b/tv.h
@@ -0,0 +1,96 @@
+/* -*-c-*-
+ *
+ * $Id: tv.h,v 1.1 1998/11/25 23:30:01 mdw Exp $
+ *
+ * Manipulation of timeval structures
+ *
+ * (c) 1998 Straylight/Edgeware
+ */
+
+/*----- Licensing notice --------------------------------------------------* 
+ *
+ * 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.
+ * 
+ * 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.
+ * 
+ * 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.h,v $
+ * Revision 1.1  1998/11/25 23:30:01  mdw
+ * New file.
+ *
+ */
+
+#ifndef TV_H
+#define TV_H
+
+#ifdef __cplusplus
+  extern "C" {
+#endif
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <sys/time.h>
+
+/*----- Functions provided ------------------------------------------------*/
+
+/* --- @tv_add@ --- *
+ *
+ * Arguments:  @struct timeval *dst@ = destination block
+ *             @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    ---
+ *
+ * Use:                Adds two timevals.
+ */
+
+extern void tv_add(struct timeval */*dst*/,
+                  const struct timeval */*a*/,
+                  const struct timeval */*b*/);
+
+/* --- @tv_sub@ --- *
+ *
+ * Arguments:  @struct timeval *dst@ = destination block
+ *             @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    ---
+ *
+ * Use:                Subtracts two timevals.
+ */
+
+extern void tv_sub(struct timeval */*dst*/,
+                  const struct timeval */*a*/,
+                  const struct timeval */*b*/);
+
+/* --- @tv_cmp@ --- *
+ *
+ * Arguments:  @const struct timeval *a, *b@ = source blocks
+ *
+ * Returns:    Less than, equal to, or greater than zero.
+ *
+ * Use:                Compares two timevals.
+ */
+
+extern int tv_cmp(const struct timeval */*a*/,
+                 const struct timeval */*b*/);
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+  }
+#endif
+
+#endif