From 9e79bea7d3f158f2fd39dda8a413843a7bec819b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 31 Oct 2010 12:51:02 +0100 Subject: [PATCH] src/utils_time.h: Add macros for converting to "struct timespec" .. .. and "struct timeval". --- src/utils_time.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/utils_time.h b/src/utils_time.h index fecf5447..0aa4fce6 100644 --- a/src/utils_time.h +++ b/src/utils_time.h @@ -41,11 +41,22 @@ typedef uint64_t cdtime_t; #define CDTIME_T_TO_DOUBLE(t) (((double) (t)) / 1073741824.0) #define DOUBLE_TO_CDTIME_T(d) ((cdtime_t) ((d) * 1073741824.0)) -#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824)) -#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824)) +#define US_TO_CDTIME_T(us) ((cdtime_t) (((double) (us)) * 1073.741824)) +#define CDTIME_T_TO_US(t) ((suseconds_t) (((double) (t)) / 1073.741824)) +#define NS_TO_CDTIME_T(ns) ((cdtime_t) (((double) (ns)) * 1.073741824)) +#define CDTIME_T_TO_NS(t) ((long) (((double) (t)) / 1.073741824)) +#define CDTIME_T_TO_TIMEVAL(t) { \ + CDTIME_T_TO_TIME_T (t), \ + CDTIME_T_TO_US (t % 1073741824) \ +} #define TIMEVAL_TO_CDTIME_T(tv) (TIME_T_TO_CDTIME_T ((tv).tv_sec) \ + US_TO_CDTIME_T ((tv).tv_usec)) + +#define CDTIME_T_TO_TIMESPEC(t) { \ + CDTIME_T_TO_TIME_T (t), \ + CDTIME_T_TO_NS (t % 1073741824) \ +} #define TIMESPEC_TO_CDTIME_T(ts) (TIME_T_TO_CDTIME_T ((ts).tv_sec) \ + NS_TO_CDTIME_T ((ts).tv_nsec)) -- 2.30.2