|
@@ -136,23 +136,11 @@ mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
|
|
#include <mach/mach_time.h>
|
|
#include <mach/mach_time.h>
|
|
#include <assert.h>
|
|
#include <assert.h>
|
|
|
|
|
|
-/* Determine if the current OSX version supports clock_gettime */
|
|
|
|
-#ifdef __APPLE__
|
|
|
|
-#include <AvailabilityMacros.h>
|
|
|
|
-#ifndef MAC_OS_X_VERSION_10_12
|
|
|
|
-#define MAC_OS_X_VERSION_10_12 101200
|
|
|
|
-#endif
|
|
|
|
-#endif
|
|
|
|
-#define CIVETWEB_APPLE_HAVE_CLOCK_GETTIME \
|
|
|
|
- defined(__APPLE__) \
|
|
|
|
- && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
|
|
|
|
-
|
|
|
|
-#if !(CIVETWEB_APPLE_HAVE_CLOCK_GETTIME)
|
|
|
|
/* clock_gettime is not implemented on OSX prior to 10.12 */
|
|
/* clock_gettime is not implemented on OSX prior to 10.12 */
|
|
-int clock_gettime(int clk_id, struct timespec *t);
|
|
|
|
|
|
+int _civet_clock_gettime(int clk_id, struct timespec *t);
|
|
|
|
|
|
int
|
|
int
|
|
-clock_gettime(int clk_id, struct timespec *t)
|
|
|
|
|
|
+_civet_clock_gettime(int clk_id, struct timespec *t)
|
|
{
|
|
{
|
|
memset(t, 0, sizeof(*t));
|
|
memset(t, 0, sizeof(*t));
|
|
if (clk_id == CLOCK_REALTIME) {
|
|
if (clk_id == CLOCK_REALTIME) {
|
|
@@ -192,7 +180,25 @@ clock_gettime(int clk_id, struct timespec *t)
|
|
}
|
|
}
|
|
return -1; /* EINVAL - Clock ID is unknown */
|
|
return -1; /* EINVAL - Clock ID is unknown */
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+/* if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined */
|
|
|
|
+#ifdef __CLOCK_AVAILABILITY
|
|
|
|
+/* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be declared
|
|
|
|
+ * but it may be NULL at runtime. So we need to check before using it. */
|
|
|
|
+int _civet_safe_clock_gettime(int clk_id, struct timespec *t);
|
|
|
|
+
|
|
|
|
+int
|
|
|
|
+_civet_safe_clock_gettime(int clk_id, struct timespec *t) {
|
|
|
|
+ if( clock_gettime ) {
|
|
|
|
+ return clock_gettime(clk_id, t);
|
|
|
|
+ }
|
|
|
|
+ return _civet_clock_gettime(clk_id, t);
|
|
|
|
+}
|
|
|
|
+#define clock_gettime _civet_safe_clock_gettime
|
|
|
|
+#else
|
|
|
|
+#define clock_gettime _civet_clock_gettime
|
|
#endif
|
|
#endif
|
|
|
|
+
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|