From 28c5665a08a0e1862d5f4e880a9d094534a5a43c Mon Sep 17 00:00:00 2001 From: stal Date: Sun, 18 May 2014 14:56:35 -0700 Subject: Fix current_time_monotonic on OS X. clock_gettime doesn't exist there, so throw in some equivalent mach stuff. --- toxcore/network.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/toxcore/network.c b/toxcore/network.c index 0505091d..2ffe067f 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -33,6 +33,12 @@ #include #endif +#ifdef __APPLE__ +#include +#include +#endif + +#include #include "network.h" #include "util.h" @@ -229,6 +235,16 @@ uint64_t current_time_monotonic(void) struct timespec monotime; #if defined(__linux__) clock_gettime(CLOCK_MONOTONIC_RAW, &monotime); +#elif defined(__APPLE__) + clock_serv_t muhclock; + mach_timespec_t machtime; + + host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &muhclock); + clock_get_time(muhclock, &machtime); + mach_port_deallocate(mach_task_self(), muhclock); + + monotime.tv_sec = machtime.tv_sec; + monotime.tv_nsec = machtime.tv_nsec; #else clock_gettime(CLOCK_MONOTONIC, &monotime); #endif -- cgit v1.2.3