On 9/28/19 3:02 PM, Richard W.M. Jones wrote:
---
common/include/test-tvdiff.c | 75 +++++++++++++++++++++++++++++-------
common/include/tvdiff.h | 13 ++++++-
2 files changed, 74 insertions(+), 14 deletions(-)
ACK
int
-main (void)
+main (int argc, char *argv[])
Not sure this part matters, but doesn't hurt either.
+++ b/common/include/tvdiff.h
@@ -40,7 +40,7 @@
#include <sys/time.h>
/* Return the number of µs (microseconds) in y - x. */
-static int64_t
+static inline int64_t
tvdiff_usec (const struct timeval *x, const struct timeval *y)
{
int64_t usec;
@@ -50,4 +50,15 @@ tvdiff_usec (const struct timeval *x, const struct timeval *y)
return usec;
}
+/* Return timeval difference as another struct timeval. z = y - x. */
+static inline void
+subtract_timeval (const struct timeval *x, const struct timeval *y,
+ struct timeval *z)
+{
+ int64_t usec = tvdiff_usec (x, y);
+
+ z->tv_sec = usec / 1000000;
+ z->tv_usec = usec % 1000000;
+}
+
#endif /* NBDKIT_TVDIFF_H */
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org