From 062f50af391f67c7cea76725c19d0df9dadb4303 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Fri, 29 Oct 2021 18:42:22 +0000 Subject: [PATCH] Fix lack of timespec_get() on Android. Some versions of the Android libc do not have timespec_get(), use clock_gettime() instead on Android. Signed-off-by: Rafael Kitover --- src/utils.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/utils.h b/src/utils.h index 13a77fa..c509893 100644 --- a/src/utils.h +++ b/src/utils.h @@ -14,6 +14,8 @@ #include +#include + #include "compiler.h" #include "types.h" @@ -277,5 +279,18 @@ allocchk_(const char *func_name, const char *file, unsigned int line, void *ptr) /// int next_power_of_two(int n); +// Some versions of the Android libc do not have timespec_get(), use +// clock_gettime() instead. +#ifdef __ANDROID__ + +#ifndef TIME_UTC +#define TIME_UTC 1 +#endif + +static inline int timespec_get(struct timespec *ts, int base) { + assert(base == TIME_UTC); + return clock_gettime(CLOCK_REALTIME, ts); +} +#endif // vim: set noet sw=8 ts=8 :