diff --git a/src/misc.c b/src/misc.c index f624bd4a..769b15e2 100644 --- a/src/misc.c +++ b/src/misc.c @@ -27,6 +27,7 @@ #endif #include +#include #include #include #include @@ -928,6 +929,21 @@ timespec_cmp(struct timespec time1, struct timespec time2) return 0; } +struct timespec +timespec_reltoabs(struct timespec relative) +{ + struct timespec absolute; + +#if _POSIX_TIMERS > 0 + clock_gettime(CLOCK_REALTIME, &absolute); +#else + struct timeval tv; + gettimeofday(&tv, NULL); + TIMEVAL_TO_TIMESPEC(&tv, &absolute); +#endif + return timespec_add(absolute, relative); +} + #if defined(HAVE_MACH_CLOCK) || defined(HAVE_MACH_TIMER) #include /* mach_absolute_time */ diff --git a/src/misc.h b/src/misc.h index c358dde9..de1a089e 100644 --- a/src/misc.h +++ b/src/misc.h @@ -145,6 +145,9 @@ timespec_add(struct timespec time1, struct timespec time2); int timespec_cmp(struct timespec time1, struct timespec time2); +struct timespec +timespec_reltoabs(struct timespec relative); + /* initialize mutex with error checking (not default on all platforms) */ int mutex_init(pthread_mutex_t *mutex);