Add back Darwin/Mach/Apple portability
Quite a few of the changes against the MalcolmRobb/dump1090 fork are incompatible with OSX. This patch adds back that cross platform support back.
This commit is contained in:
parent
ef34c4ce0f
commit
ae126d1009
14 changed files with 324 additions and 10 deletions
49
compat/clock_nanosleep/clock_nanosleep.c
Normal file
49
compat/clock_nanosleep/clock_nanosleep.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* clock_nanosleep.c - clock_nanosleep() replacement
|
||||
*/
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include "clock_nanosleep.h"
|
||||
#include <errno.h> // for errno, EINVAL
|
||||
#include <time.h> // for nanosleep, NULL
|
||||
#include "../clock_gettime/clock_gettime.h" // for clock_gettime
|
||||
|
||||
int clock_nanosleep(clockid_t id, int flags, const struct timespec *ts,
|
||||
struct timespec *ots) {
|
||||
int ret;
|
||||
|
||||
if (id != CLOCK_REALTIME)
|
||||
return EINVAL;
|
||||
|
||||
if (flags & TIMER_ABSTIME) {
|
||||
struct timespec mine;
|
||||
|
||||
if (clock_gettime(id, &mine))
|
||||
return errno;
|
||||
|
||||
if (mine.tv_sec > ts->tv_sec)
|
||||
return 0; // behind schedule
|
||||
|
||||
if (mine.tv_nsec > ts->tv_nsec) {
|
||||
if (mine.tv_sec == ts->tv_sec)
|
||||
return 0; // behind schedule too
|
||||
|
||||
mine.tv_nsec = 1000000000 + ts->tv_nsec - mine.tv_nsec;
|
||||
mine.tv_sec++;
|
||||
}
|
||||
else
|
||||
mine.tv_nsec = ts->tv_nsec - mine.tv_nsec;
|
||||
|
||||
mine.tv_sec = ts->tv_sec - mine.tv_sec;
|
||||
|
||||
/* With TIMER_ABSTIME, clock_nanosleep ignores <ots> */
|
||||
ret = nanosleep(&mine, NULL);
|
||||
}
|
||||
else
|
||||
ret = nanosleep(ts, ots);
|
||||
|
||||
return ret ? errno : 0;
|
||||
}
|
||||
|
||||
#endif // __APPLE__
|
Loading…
Add table
Add a link
Reference in a new issue