1 /* 2 * lowlevel binder for macosx and 3 */ 4 #include <time.h> 5 #if defined __MACH__ && !defined __GNU__ 6 #include <mach/clock.h> 7 #include <mach/mach.h> 8 #endif 9 10 /* on mac os X, clock_gettime doesn't exists, but 11 * http://stackoverflow.com/questions/5167269/clock-gettime-alternative-in-mac-os-x 12 * 13 * we ignore errors as it's very very unlikely considering the hardcoded ID 14 * and the fact that haskell should call this code. 15 */ hourglass_clock_calendar(struct timespec * timespec)16void hourglass_clock_calendar(struct timespec *timespec) 17 { 18 #if defined __MACH__ && !defined __GNU__ 19 clock_serv_t cclock; 20 mach_timespec_t mts; 21 22 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); 23 clock_get_time(cclock, &mts); 24 mach_port_deallocate(mach_task_self(), cclock); 25 26 timespec->tv_sec = mts.tv_sec; 27 timespec->tv_nsec = mts.tv_nsec; 28 #else 29 clock_gettime(CLOCK_REALTIME, timespec); 30 #endif 31 } 32