]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
include: add indirect monotonic clock id specifier
authorSami Kerola <kerolasa@iki.fi>
Mon, 7 Jan 2019 21:31:34 +0000 (21:31 +0000)
committerSami Kerola <kerolasa@iki.fi>
Sat, 12 Jan 2019 08:46:53 +0000 (08:46 +0000)
Avoid repeated ifdef checks in code by adding a project specific
preprocessor definition.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
include/monotonic.h
lib/monotonic.c

index a499fa34ac4c03170a11f3911f2d8c85d756a6ea..296173ecec3dc61711365a3ad9afb799b9b511fb 100644 (file)
@@ -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);
index bb58e15d7b5086437b6117c43b6a6766b1075cbb..96ead1ee0d7aebe2fa6fe3178f4409218b5b0747 100644 (file)
@@ -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;
        }