+struct timespec time_from_usec(uint64_t usec);
+
+/**
+ * time_from_nsec - convert nanoseconds to a timespec
+ * @nsec: time in nanoseconds
+ *
+ * Example:
+ * // 1/2 second timeout
+ * #define TIMEOUT time_from_nsec(500000000)
+ */
+struct timespec time_from_nsec(uint64_t nsec);
+
+/**
+ * timespec_to_timeval - convert a timespec to a timeval.
+ * @ts: a timespec.
+ *
+ * Example:
+ * struct timeval tv;
+ *
+ * tv = timespec_to_timeval(time_now());
+ */
+static inline struct timeval timespec_to_timeval(struct timespec ts)
+{
+ struct timeval tv;
+ tv.tv_sec = ts.tv_sec;
+ tv.tv_usec = ts.tv_nsec / 1000;
+ return tv;
+}
+
+/**
+ * timeval_to_timespec - convert a timeval to a timespec.
+ * @tv: a timeval.
+ *
+ * Example:
+ * struct timeval tv = { 0, 500 };
+ * struct timespec ts;
+ *
+ * ts = timeval_to_timespec(tv);
+ */
+static inline struct timespec timeval_to_timespec(struct timeval tv)
+{
+ struct timespec ts;
+ ts.tv_sec = tv.tv_sec;
+ ts.tv_nsec = tv.tv_usec * 1000;
+ return ts;
+}
+
+/**
+ * time_check - check if a time is malformed.
+ * @in: the time to check (returned)
+ * @abortstr: the string to print to stderr before aborting (if set).
+ *
+ * This can be used to make sure a time isn't negative and doesn't
+ * have a tv_nsec >= 1000000000. If it is, and @abortstr is non-NULL,
+ * that will be printed and abort() is called. Otherwise, if
+ * @abortstr is NULL then the returned timespec will be normalized and
+ * tv_sec set to 0 if it was negative.
+ *
+ * Note that if ccan/time is compiled with DEBUG, then it will call this
+ * for all passed and returned times.
+ *
+ * Example:
+ * printf("Now is %lu seconds since epoch\n",
+ * (long)time_check(time_now(), "time_now() failed?").tv_sec);
+ */
+struct timespec time_check(struct timespec in, const char *abortstr);