diff options
Diffstat (limited to 'lib/gettime.c')
-rw-r--r-- | lib/gettime.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/lib/gettime.c b/lib/gettime.c index 9a4e342f18e..171f22476f8 100644 --- a/lib/gettime.c +++ b/lib/gettime.c @@ -28,21 +28,24 @@ void gettime (struct timespec *ts) { -#if HAVE_NANOTIME +#if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME + clock_gettime (CLOCK_REALTIME, ts); +#elif HAVE_NANOTIME nanotime (ts); #else + struct timeval tv; + gettimeofday (&tv, NULL); + ts->tv_sec = tv.tv_sec; + ts->tv_nsec = tv.tv_usec * 1000; +#endif +} -# if defined CLOCK_REALTIME && HAVE_CLOCK_GETTIME - if (clock_gettime (CLOCK_REALTIME, ts) == 0) - return; -# endif - - { - struct timeval tv; - gettimeofday (&tv, NULL); - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; - } +/* Return the current system time as a struct timespec. */ -#endif +struct timespec +current_timespec (void) +{ + struct timespec ts; + gettime (&ts); + return ts; } |