diff options
author | Sami Kerola | 2019-01-07 22:31:34 +0100 |
---|---|---|
committer | Sami Kerola | 2019-01-12 09:46:53 +0100 |
commit | ee6e39305c55d04e647c294898568ed1d3699638 (patch) | |
tree | e33e68f4129f2b5faafd6264b0588a7eee763470 | |
parent | timeutils: match today day and this year correctly (diff) | |
download | kernel-qcow2-util-linux-ee6e39305c55d04e647c294898568ed1d3699638.tar.gz kernel-qcow2-util-linux-ee6e39305c55d04e647c294898568ed1d3699638.tar.xz kernel-qcow2-util-linux-ee6e39305c55d04e647c294898568ed1d3699638.zip |
include: add indirect monotonic clock id specifier
Avoid repeated ifdef checks in code by adding a project specific
preprocessor definition.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | include/monotonic.h | 6 | ||||
-rw-r--r-- | lib/monotonic.c | 6 |
2 files changed, 7 insertions, 5 deletions
diff --git a/include/monotonic.h b/include/monotonic.h index a499fa34a..296173ece 100644 --- a/include/monotonic.h +++ b/include/monotonic.h @@ -1,6 +1,12 @@ #ifndef UTIL_LINUX_MONOTONIC_H #define UTIL_LINUX_MONOTONIC_H +# ifdef CLOCK_MONOTONIC_RAW +# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC_RAW +# else +# define UL_CLOCK_MONOTONIC CLOCK_MONOTONIC +# endif + #include <sys/time.h> extern int get_boot_time(struct timeval *boot_time); diff --git a/lib/monotonic.c b/lib/monotonic.c index bb58e15d7..96ead1ee0 100644 --- a/lib/monotonic.c +++ b/lib/monotonic.c @@ -52,12 +52,8 @@ int gettime_monotonic(struct timeval *tv) int ret; struct timespec ts; -# ifdef CLOCK_MONOTONIC_RAW /* Linux specific, can't slew */ - if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) { -# else - if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) { -# endif + if (!(ret = clock_gettime(UL_CLOCK_MONOTONIC, &ts))) { tv->tv_sec = ts.tv_sec; tv->tv_usec = ts.tv_nsec / 1000; } |