Commit 1bcd9a43b123323b0a63f176c9452373228d3aaa

Con Kolivas 2013-08-18T00:34:01

Provide a us_to_timespec helper function.

diff --git a/util.c b/util.c
index 61591dc..c012ba2 100644
--- a/util.c
+++ b/util.c
@@ -908,6 +908,12 @@ void us_to_timeval(struct timeval *val, int64_t us)
 	val->tv_usec = us - (val->tv_sec * 1000000);
 }
 
+void us_to_timespec(struct timespec *spec, int64_t us)
+{
+	spec->tv_sec = us / 1000000;
+	spec->tv_nsec = (us - (spec->tv_sec * 1000000)) * 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 3cc7ffe..a3d8163 100644
--- a/util.h
+++ b/util.h
@@ -81,6 +81,7 @@ 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);
 void us_to_timeval(struct timeval *val, int64_t us);
+void us_to_timespec(struct timespec *spec, int64_t us);
 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);