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 <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2021-10-29 18:42:22 +00:00
parent ad18d129cc
commit 062f50af39
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,8 @@
#include <test.h>
#include <time.h>
#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 :