diff --git a/libowlps/libowlps.c b/libowlps/libowlps.c index 91314dd..af8621d 100644 --- a/libowlps/libowlps.c +++ b/libowlps/libowlps.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -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 ; }