Fallback for earlier Apple platforms that lack clock_gettime
@@ -463,6 +463,13 @@ static int upnp_gettimeofday(struct timeval * tv)
tv->tv_usec = (ts % 1000) * 1000;
return 0; /* success */
#elif defined(CLOCK_MONOTONIC_FAST) || defined(CLOCK_MONOTONIC)
+#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)
@@ -471,6 +478,14 @@ static int upnp_gettimeofday(struct timeval * tv)
tv->tv_usec = ts.tv_nsec / 1000;
}
return ret_code;
+#if defined(__APPLE__)
+ }
+ else
+ {
+ // fall-back for earlier Apple platforms
+ return gettimeofday(tv, NULL);
+ }
+#endif // defined(__APPLE__)
#else
return gettimeofday(tv, NULL);
#endif
