Disable monotonic clock in sdb to fix build on some linux distros

This commit is contained in:
pancake 2015-01-20 21:44:23 +01:00
parent e1f8bce721
commit 546d5d2070
3 changed files with 22 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -1,11 +1,10 @@
/* sdb - LGPLv3 - Copyright 2011-2015 - pancake */
#include "sdb.h"
#if __linux__
#define GETTIMEOFDAY 0
#if USE_MONOTONIC_CLOCK
#include <time.h>
#else
#define GETTIMEOFDAY 1
#include <sys/time.h>
#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) {