| 83 | #include <mach/mach_time.h> |
| 84 | |
| 85 | static int clock_gettime(clockid_t clock_id, struct timespec *tp) |
| 86 | { |
| 87 | if (clock_id == CLOCK_REALTIME) |
| 88 | { |
| 89 | struct timeval t; |
| 90 | |
| 91 | if (gettimeofday(&t, NULL) != 0) |
| 92 | { |
| 93 | return -1; |
| 94 | } |
| 95 | |
| 96 | tp->tv_sec = t.tv_sec; |
| 97 | tp->tv_nsec = t.tv_usec * 1000; |
| 98 | } |
| 99 | else if (clock_id == CLOCK_MONOTONIC) |
| 100 | { |
| 101 | static mach_timebase_info_data_t info = { 0, 0 }; |
| 102 | |
| 103 | if (info.denom == 0) |
| 104 | { |
| 105 | mach_timebase_info(&info); |
| 106 | } |
| 107 | |
| 108 | uint64_t t = mach_absolute_time() * info.numer / info.denom; |
| 109 | tp->tv_sec = t / 1000000000; |
| 110 | tp->tv_nsec = t % 1000000000; |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | errno = EINVAL; |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | #endif // !HAVE_CLOCK_GETTIME |
| 122 |
no test coverage detected