Merge branch 'apple_clock_gettime_fallback_1'

see #516
This commit is contained in:
Thomas Bernard 2021-05-12 00:09:48 +02:00
commit f13a79fabc
1 changed files with 22 additions and 7 deletions

View File

@ -469,14 +469,29 @@ static int upnp_gettimeofday(struct timeval * tv)
tv->tv_usec = (ts % 1000) * 1000;
return 0; /* success */
#elif defined(CLOCK_MONOTONIC_FAST) || defined(CLOCK_MONOTONIC)
struct timespec ts;
int ret_code = clock_gettime(UPNP_CLOCKID, &ts);
if (ret_code == 0)
{
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
#if defined(__APPLE__)
#if defined(__clang__)
if (__builtin_available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *)) {
#else /* !defined(__clang__) */
if (clock_gettime != NULL) {
#endif /* defined(__clang__) */
#endif /* defined(__APPLE__) */
struct timespec ts;
int ret_code = clock_gettime(UPNP_CLOCKID, &ts);
if (ret_code == 0)
{
tv->tv_sec = ts.tv_sec;
tv->tv_usec = ts.tv_nsec / 1000;
}
return ret_code;
#if defined(__APPLE__)
}
return ret_code;
else
{
/* fall-back for earlier Apple platforms */
return gettimeofday(tv, NULL);
}
#endif /* defined(__APPLE__) */
#else
return gettimeofday(tv, NULL);
#endif