MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / clock_gettime

Function clock_gettime

src/misc.c:85–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83#include <mach/mach_time.h>
84
85static 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

Callers 4

monotonic_secondsFunction · 0.85
rig_cookieFunction · 0.85
hl_usleepFunction · 0.85
elapsed_msFunction · 0.85

Calls 1

gettimeofdayFunction · 0.85

Tested by

no test coverage detected