summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2014-11-19 11:54:47 +0100
committerKarel Zak2014-11-19 11:54:47 +0100
commitcd2876d252215fb3fbe46f787cb37cd4fbd64e53 (patch)
tree8b12443080179b8e99a010b88b0446c061711e66 /lib
parentbuild-sys: use CLOCKGETTIME_LIBS (diff)
downloadkernel-qcow2-util-linux-cd2876d252215fb3fbe46f787cb37cd4fbd64e53.tar.gz
kernel-qcow2-util-linux-cd2876d252215fb3fbe46f787cb37cd4fbd64e53.tar.xz
kernel-qcow2-util-linux-cd2876d252215fb3fbe46f787cb37cd4fbd64e53.zip
build-sys: move all around clock_gettime() to monotonic.c
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/monotonic.c (renamed from lib/boottime.c)29
-rw-r--r--lib/timeutils.c23
2 files changed, 27 insertions, 25 deletions
diff --git a/lib/boottime.c b/lib/monotonic.c
index f9366bd33..3d4a4438e 100644
--- a/lib/boottime.c
+++ b/lib/monotonic.c
@@ -1,11 +1,14 @@
-
+/*
+ * Please, don't add this file to libcommon because clock_gettime() requires
+ * -lrt on systems with old libc.
+ */
#include <time.h>
#include <sys/sysinfo.h>
#include <sys/time.h>
#include "c.h"
#include "nls.h"
-#include "boottime.h"
+#include "monotonic.h"
int get_boot_time(struct timeval *boot_time)
{
@@ -41,3 +44,25 @@ int get_boot_time(struct timeval *boot_time)
return -ENOSYS;
#endif
}
+
+int gettime_monotonic(struct timeval *tv)
+{
+#ifdef CLOCK_MONOTONIC
+ /* Can slew only by ntp and adjtime */
+ int ret;
+ struct timespec ts;
+
+# ifdef CLOCK_MONOTONIC_RAW
+ /* Linux specific, cant slew */
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
+# else
+ if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
+# endif
+ tv->tv_sec = ts.tv_sec;
+ tv->tv_usec = ts.tv_nsec / 1000;
+ }
+ return ret;
+#else
+ return gettimeofday(tv, NULL);
+#endif
+}
diff --git a/lib/timeutils.c b/lib/timeutils.c
index bd3d40248..b811041e4 100644
--- a/lib/timeutils.c
+++ b/lib/timeutils.c
@@ -340,26 +340,3 @@ int parse_timestamp(const char *t, usec_t *usec)
return 0;
}
-
-
-int gettime_monotonic(struct timeval *tv)
-{
-#ifdef CLOCK_MONOTONIC
- /* Can slew only by ntp and adjtime */
- int ret;
- struct timespec ts;
-
-# ifdef CLOCK_MONOTONIC_RAW
- /* Linux specific, cant slew */
- if (!(ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts))) {
-# else
- if (!(ret = clock_gettime(CLOCK_MONOTONIC, &ts))) {
-# endif
- tv->tv_sec = ts.tv_sec;
- tv->tv_usec = ts.tv_nsec / 1000;
- }
- return ret;
-#else
- return gettimeofday(tv, NULL);
-#endif
-}