summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Aaron Burghardt2015-07-30 15:31:50 -0400
committerGravatar Nikias Bassen2016-01-28 16:20:32 +0100
commitfc3982fa1e3e8972f8f49e2e35eef82e02f1deaf (patch)
tree04dd93adc29d2ab10a361fce8e5ddb95216cd400
parent726db697a22b4eb3de4ce8e2c8697cc16465c73a (diff)
downloadusbmuxd-fc3982fa1e3e8972f8f49e2e35eef82e02f1deaf.tar.gz
usbmuxd-fc3982fa1e3e8972f8f49e2e35eef82e02f1deaf.tar.bz2
Add a static clock_gettime() substitute for OS X.
-rw-r--r--src/utils.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index ceb65e1..67860b3 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -30,6 +30,9 @@
#include <stdarg.h>
#include <time.h>
#include <sys/time.h>
+#ifdef __APPLE__
+#include <mach/mach_time.h>
+#endif
#include "utils.h"
@@ -299,6 +302,36 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form
return 1;
}
+#ifdef __APPLE__
+typedef int clockid_t;
+#define CLOCK_MONOTONIC 1
+
+static int clock_gettime(clockid_t clk_id, struct timespec *ts)
+{
+ // See http://developer.apple.com/library/mac/qa/qa1398
+
+ uint64_t mach_time, nano_sec;
+
+ static mach_timebase_info_data_t base_info;
+
+ mach_time = mach_absolute_time();
+
+ if (base_info.denom == 0) {
+ (void) mach_timebase_info(&base_info);
+ }
+
+ if (base_info.numer == 1 && base_info.denom == 1)
+ nano_sec = mach_time;
+ else
+ nano_sec = mach_time * base_info.numer / base_info.denom;
+
+ ts->tv_sec = nano_sec / 1000000000;
+ ts->tv_nsec = nano_sec % 1000000000;
+
+ return 0;
+}
+#endif
+
void get_tick_count(struct timeval * tv)
{
struct timespec ts;