apple_gettime.patch 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. diff --git a/reproc/src/clock.posix.c b/reproc/src/clock.posix.c
  2. index 8d22a3b..4d47fa3 100644
  3. --- a/reproc/src/clock.posix.c
  4. +++ b/reproc/src/clock.posix.c
  5. @@ -6,11 +6,39 @@
  6. #include "error.h"
  7. +#if defined __APPLE__ && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
  8. +#include <Availability.h>
  9. + #ifndef CLOCK_REALTIME
  10. + #define CLOCK_REALTIME 0
  11. + #endif
  12. +
  13. + #include <mach/clock.h>
  14. + #include <mach/mach.h>
  15. + #include <sys/time.h>
  16. +
  17. + int alt_clock_gettime (int clock_id, struct timespec *ts)
  18. + {
  19. + clock_serv_t cclock;
  20. + mach_timespec_t mts;
  21. + host_get_clock_service (mach_host_self (), clock_id, &cclock);
  22. + clock_get_time (cclock, &mts);
  23. + mach_port_deallocate (mach_task_self (), cclock);
  24. + ts->tv_sec = mts.tv_sec;
  25. + ts->tv_nsec = mts.tv_nsec;
  26. + return 0;
  27. + }
  28. +#endif
  29. +
  30. +
  31. int64_t now(void)
  32. {
  33. struct timespec timespec = { 0 };
  34. +#if defined __APPLE__ && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
  35. + int r = alt_clock_gettime(CLOCK_REALTIME, &timespec);
  36. +#else
  37. int r = clock_gettime(CLOCK_REALTIME, &timespec);
  38. +#endif
  39. ASSERT_UNUSED(r == 0);
  40. return timespec.tv_sec * 1000 + timespec.tv_nsec / 1000000;