From 546d5d20706fbf5e3cf18d00a405bf4b5894d6d7 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 20 Jan 2015 21:44:23 +0100 Subject: [PATCH] Disable monotonic clock in sdb to fix build on some linux distros --- libr/include/sdb/config.h | 2 ++ shlr/sdb/src/config.h | 2 ++ shlr/sdb/src/util.c | 38 ++++++++++++++++++-------------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libr/include/sdb/config.h b/libr/include/sdb/config.h index 85cfd12ca9..7eaa88c7d9 100644 --- a/libr/include/sdb/config.h +++ b/libr/include/sdb/config.h @@ -2,6 +2,8 @@ #define CONFIG_H #define SDB_KEYSIZE 32 +/* only available on linux, and some distros require -lrt */ +#define USE_MONOTONIC_CLOCK 0 #if SDB_KEYSIZE == 32 #define SDB_KT ut32 diff --git a/shlr/sdb/src/config.h b/shlr/sdb/src/config.h index 85cfd12ca9..7eaa88c7d9 100644 --- a/shlr/sdb/src/config.h +++ b/shlr/sdb/src/config.h @@ -2,6 +2,8 @@ #define CONFIG_H #define SDB_KEYSIZE 32 +/* only available on linux, and some distros require -lrt */ +#define USE_MONOTONIC_CLOCK 0 #if SDB_KEYSIZE == 32 #define SDB_KT ut32 diff --git a/shlr/sdb/src/util.c b/shlr/sdb/src/util.c index 24aaec633f..d8ce1c61f2 100644 --- a/shlr/sdb/src/util.c +++ b/shlr/sdb/src/util.c @@ -1,11 +1,10 @@ /* sdb - LGPLv3 - Copyright 2011-2015 - pancake */ #include "sdb.h" -#if __linux__ -#define GETTIMEOFDAY 0 + +#if USE_MONOTONIC_CLOCK #include #else -#define GETTIMEOFDAY 1 #include #endif @@ -157,37 +156,36 @@ SDB_API const char *sdb_const_anext(const char *str, const char **next) { } SDB_API ut64 sdb_now () { -#if GETTIMEOFDAY - struct timeval now; - if (!gettimeofday (&now, NULL)) - return now.tv_sec; -#else +#if USE_MONOTINIC_CLOCK struct timespec ts; if (!clock_gettime (CLOCK_MONOTONIC, &ts)) return ts.tv_sec; +#else + struct timeval now; + if (!gettimeofday (&now, NULL)) + return now.tv_sec; #endif return 0LL; } SDB_API ut64 sdb_unow () { - ut64 x; -#if GETTIMEOFDAY - struct timeval now; - if (!gettimeofday (&now, NULL)) { - x = now.tv_sec; - x <<= 32; - x += now.tv_usec; - } else x = 0LL; - return x; -#else + ut64 x = 0LL; +#if USE_MONOTONIC_CLOCK struct timespec ts; if (!clock_gettime (CLOCK_MONOTONIC, &ts)) { x = ts.tv_sec; x <<= 32; x += ts.tv_nsec/1000; - } else x = 0LL; - return x; + } +#else + struct timeval now; + if (!gettimeofday (&now, NULL)) { + x = now.tv_sec; + x <<= 32; + x += now.tv_usec; + } #endif + return x; } SDB_API int sdb_isnum (const char *s) {