[lib] timestamp_now(): gettimeofday() if needed
Use gettimeofday() when clock_gettime() is not available.
This commit is contained in:
parent
e98474e678
commit
9f8c85d9c7
|
@ -15,6 +15,7 @@
|
|||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
@ -177,14 +178,26 @@ int owl_msleep(uint32_t time_ms)
|
|||
int owl_timestamp_now(owl_timestamp *const now)
|
||||
{
|
||||
int ret ;
|
||||
|
||||
#if _POSIX_TIMERS > 0
|
||||
struct timespec now_ts ;
|
||||
if ((ret = clock_gettime(CLOCK_REALTIME, &now_ts)))
|
||||
ret = clock_gettime(CLOCK_REALTIME, &now_ts) ;
|
||||
#else // _POSIX_TIMERS
|
||||
struct timeval now_ts ;
|
||||
ret = gettimeofday(&now_ts, NULL) ;
|
||||
#endif // _POSIX_TIMERS
|
||||
|
||||
if (ret)
|
||||
{
|
||||
perror("Cannot get the current time") ;
|
||||
return ret ;
|
||||
}
|
||||
|
||||
#if _POSIX_TIMERS > 0
|
||||
owl_timespec_to_timestamp(&now_ts, now) ;
|
||||
#else // _POSIX_TIMERS
|
||||
owl_timeval_to_timestamp(&now_ts, now) ;
|
||||
#endif // _POSIX_TIMERS
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue