diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2020-12-13 13:16:44 +0100 |
---|---|---|
committer | BenBE <BenBE@geshi.org> | 2020-12-18 22:43:21 +0100 |
commit | 26993d2d2b2be391adbfaa2ee53ee3e77f323b28 (patch) | |
tree | 574d7584b410a403bbf5ca89cd01ec3c3290ac64 /Compat.c | |
parent | 0401df8cbd3193a43e616e36244e0811376afbfd (diff) |
Support clock_gettime() on OSX El Capitan and earlier
Diffstat (limited to 'Compat.c')
-rw-r--r-- | Compat.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -11,12 +11,18 @@ in the source distribution for its full text. #include <errno.h> #include <fcntl.h> // IWYU pragma: keep +#include <time.h> #include <unistd.h> #include <sys/stat.h> #include <sys/types.h> // IWYU pragma: keep #include "XUtils.h" // IWYU pragma: keep +#ifdef HAVE_HOST_GET_CLOCK_SERVICE +#include <mach/clock.h> +#include <mach/mach.h> +#endif + int Compat_faccessat(int dirfd, const char* pathname, @@ -117,3 +123,31 @@ ssize_t Compat_readlinkat(int dirfd, #endif } + +int Compat_clock_monotonic_gettime(struct timespec *tp) { + +#if defined(HAVE_CLOCK_GETTIME) + + return clock_gettime(CLOCK_MONOTONIC, tp); + +#elif defined(HAVE_HOST_GET_CLOCK_SERVICE) + + clock_serv_t cclock; + mach_timespec_t mts; + + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + + tp->tv_sec = mts.tv_sec; + tp->tv_nsec = mts.tv_nsec; + + return 0; + +#else + +#error No Compat_clock_monotonic_gettime() implementation! + +#endif + +} |