summaryrefslogtreecommitdiffstats
path: root/src/utils.c
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 /src/utils.c
parent726db697a22b4eb3de4ce8e2c8697cc16465c73a (diff)
downloadusbmuxd-fc3982fa1e3e8972f8f49e2e35eef82e02f1deaf.tar.gz
usbmuxd-fc3982fa1e3e8972f8f49e2e35eef82e02f1deaf.tar.bz2
Add a static clock_gettime() substitute for OS X.
Diffstat (limited to 'src/utils.c')
-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 @@
30#include <stdarg.h> 30#include <stdarg.h>
31#include <time.h> 31#include <time.h>
32#include <sys/time.h> 32#include <sys/time.h>
33#ifdef __APPLE__
34#include <mach/mach_time.h>
35#endif
33 36
34#include "utils.h" 37#include "utils.h"
35 38
@@ -299,6 +302,36 @@ int plist_write_to_filename(plist_t plist, const char *filename, enum plist_form
299 return 1; 302 return 1;
300} 303}
301 304
305#ifdef __APPLE__
306typedef int clockid_t;
307#define CLOCK_MONOTONIC 1
308
309static int clock_gettime(clockid_t clk_id, struct timespec *ts)
310{
311 // See http://developer.apple.com/library/mac/qa/qa1398
312
313 uint64_t mach_time, nano_sec;
314
315 static mach_timebase_info_data_t base_info;
316
317 mach_time = mach_absolute_time();
318
319 if (base_info.denom == 0) {
320 (void) mach_timebase_info(&base_info);
321 }
322
323 if (base_info.numer == 1 && base_info.denom == 1)
324 nano_sec = mach_time;
325 else
326 nano_sec = mach_time * base_info.numer / base_info.denom;
327
328 ts->tv_sec = nano_sec / 1000000000;
329 ts->tv_nsec = nano_sec % 1000000000;
330
331 return 0;
332}
333#endif
334
302void get_tick_count(struct timeval * tv) 335void get_tick_count(struct timeval * tv)
303{ 336{
304 struct timespec ts; 337 struct timespec ts;