Add helper functions to convert timespec to timeval and vice versa.
diff --git a/util.c b/util.c
index 7fc41fc..ef87dc3 100644
--- a/util.c
+++ b/util.c
@@ -890,6 +890,18 @@ void copy_time(struct timeval *dest, const struct timeval *src)
memcpy(dest, src, sizeof(struct timeval));
}
+void timespec_to_val(struct timeval *val, const struct timespec *spec)
+{
+ val->tv_sec = spec->tv_sec;
+ val->tv_usec = spec->tv_nsec / 1000;
+}
+
+void timeval_to_spec(struct timespec *spec, const struct timeval *val)
+{
+ spec->tv_sec = val->tv_sec;
+ spec->tv_nsec = val->tv_usec * 1000;
+}
+
/* Returns the microseconds difference between end and start times as a double */
double us_tdiff(struct timeval *end, struct timeval *start)
{
diff --git a/util.h b/util.h
index dd17931..b573220 100644
--- a/util.h
+++ b/util.h
@@ -78,6 +78,8 @@ void addtime(struct timeval *a, struct timeval *b);
bool time_more(struct timeval *a, struct timeval *b);
bool time_less(struct timeval *a, struct timeval *b);
void copy_time(struct timeval *dest, const struct timeval *src);
+void timespec_to_val(struct timeval *val, const struct timespec *spec);
+void timeval_to_spec(struct timespec *spec, const struct timeval *val);
double us_tdiff(struct timeval *end, struct timeval *start);
double tdiff(struct timeval *end, struct timeval *start);
bool stratum_send(struct pool *pool, char *s, ssize_t len);