/* -*-c-*-
*
- * $Id: tv.c,v 1.3 1999/05/06 19:51:36 mdw Exp $
+ * $Id: tv.c,v 1.5 1999/05/21 22:13:12 mdw Exp $
*
* Manipulation of timeval structures
*
/*----- Revision history --------------------------------------------------*
*
* $Log: tv.c,v $
+ * Revision 1.5 1999/05/21 22:13:12 mdw
+ * Moved most of the code into exported macros. The main functions now
+ * implemented using the macros.
+ *
+ * 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.
*
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@ --- *
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@ --- *
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)