Skip to content

Instantly share code, notes, and snippets.

@dreid
Created October 2, 2011 00:01
Show Gist options
  • Save dreid/1256839 to your computer and use it in GitHub Desktop.
Save dreid/1256839 to your computer and use it in GitHub Desktop.
nacl osx patch by @pr0zac
--- nacl-20110221/curvecp/nanoseconds.c 2011-02-20 17:49:34.000000000 -0800
+++ NaCl/curvecp/nanoseconds.c 2011-10-01 16:56:43.000000000 -0700
@@ -1,4 +1,8 @@
#include <time.h>
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif
#include "nanoseconds.h"
/* XXX: Y2036 problems; should upgrade to a 128-bit type for this */
@@ -7,6 +11,17 @@
long long nanoseconds(void)
{
struct timespec t;
+
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+ clock_serv_t cclock;
+ mach_timespec_t mts;
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+ clock_get_time(cclock, &mts);
+ mach_port_deallocate(mach_task_self(), cclock);
+ t.tv_sec = mts.tv_sec;
+ t.tv_nsec = mts.tv_nsec;
+#else
if (clock_gettime(CLOCK_REALTIME,&t) != 0) return -1;
+#endif
return t.tv_sec * 1000000000LL + t.tv_nsec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment