Added two new functions: nstime_diff() and nstime_subtract().
authorstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 27 Oct 2010 07:44:26 +0000 (07:44 +0000)
committerstig <stig@f5534014-38df-0310-8fa8-9805f1628bb7>
Wed, 27 Oct 2010 07:44:26 +0000 (07:44 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@34660 f5534014-38df-0310-8fa8-9805f1628bb7

epan/libwireshark.def
epan/nstime.c
epan/nstime.h

index 35f3aba33c11a1ba3466cd4ded9000864acd1574..bcc35e8c5d6f00b84598e24686fa9a0938b79bf8 100644 (file)
@@ -646,6 +646,7 @@ new_create_dissector_handle
 new_register_dissector
 nstime_cmp
 nstime_delta
+nstime_diff
 nstime_is_unset
 nstime_is_zero
 nstime_set_unset
index da7fc35e05696f61a2b9b378ee5c52f63e65feaa..7ceaf8e9753b78f59b40d66a96c6774f9efffa95 100644 (file)
@@ -130,6 +130,24 @@ void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
     }
 }
 
+/*
+ * function: nstime_diff
+ * diff = a - b
+ */
+
+void nstime_diff(nstime_t *diff, const nstime_t *a, const nstime_t *b)
+{
+    diff->secs = a->secs - b->secs;
+    diff->nsecs = a->nsecs - b->nsecs;
+    if(diff->nsecs>=NS_PER_S || (diff->nsecs>0 && diff->secs<0)){
+        diff->nsecs-=NS_PER_S;
+        diff->secs++;
+    } else if(diff->nsecs<=-NS_PER_S || (diff->nsecs<0 && diff->secs>0)) {
+        diff->nsecs+=NS_PER_S;
+        diff->secs--;
+    }
+}
+
 /*
  * function: nstime_cmp
  *
index a9c11abb05d3f93027506ae9149a63685d3d6378..82b9f8319a50633b5b278ea91f63db2b9e8c0e72 100644 (file)
@@ -74,9 +74,21 @@ extern void nstime_delta(nstime_t *delta, const nstime_t *b, const nstime_t *a )
  */
 extern void nstime_sum(nstime_t *sum, const nstime_t *b, const nstime_t *a );
 
+/** calculate the difference between two times
+ *
+ * diff = a-b
+ *
+ * Note that it is acceptable for two or more of the arguments to point at the
+ * same structure.
+ */
+extern void nstime_diff(nstime_t *diff, const nstime_t *b, const nstime_t *a );
+
 /** sum += a */
 #define nstime_add(sum, a) nstime_sum(sum, sum, a)
 
+/** sum -= a */
+#define nstime_subtract(sum, a) nstime_diff(sum, sum, a)
+
 /** compare two times are return a value similar to memcmp() or strcmp().
  *
  * a > b : > 0