Skip to content

Commit

Permalink
util: use HAVE_GETTIMEOFDAY where appropriate
Browse files Browse the repository at this point in the history
configure.ac already defined HAVE_GETTIMEOFDAY, but the uses of gettimeofday()
weren't guarded by it. It obviously doesn't matter on any currently supported
platforms, but it will be needed for planned changes.
  • Loading branch information
kgaillot authored and chrissie-c committed Feb 14, 2022
1 parent 354c0c2 commit da12cc9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ qb_util_nano_from_epoch_get(void)
nano_monotonic =
(ts.tv_sec * QB_TIME_NS_IN_SEC) + (uint64_t) ts.tv_nsec;
return (nano_monotonic);
#else
#elif defined(HAVE_GETTIMEOFDAY)
uint64_t nano_from_epoch;
struct timeval time_from_epoch;
gettimeofday(&time_from_epoch, 0);
Expand All @@ -184,6 +184,8 @@ qb_util_nano_from_epoch_get(void)
(time_from_epoch.tv_usec * QB_TIME_NS_IN_USEC));

return (nano_from_epoch);
#else
#error No high-resolution clock available
#endif /* HAVE_MONOTONIC_CLOCK */
}

Expand Down Expand Up @@ -213,14 +215,16 @@ qb_util_timespec_from_epoch_get(struct timespec *ts)
{
#ifdef HAVE_MONOTONIC_CLOCK
clock_gettime(QB_CLOCK_REALTIME, ts);
#else
#elif defined(HAVE_GETTIMEOFDAY)
struct timeval time_from_epoch;
gettimeofday(&time_from_epoch, 0);

#ifndef S_SPLINT_S
ts->tv_sec = time_from_epoch.tv_sec;
ts->tv_nsec = time_from_epoch.tv_usec * QB_TIME_NS_IN_USEC;
#endif /* S_SPLINT_S */
#else
#error No high-resolution clock available
#endif /* HAVE_MONOTONIC_CLOCK */
}

Expand Down

0 comments on commit da12cc9

Please sign in to comment.