1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-12-22 04:02:04 +03:00

Second fix attempt for issue 349.

This is the only way to safely call clock_gettime (that I know of) when compiling for OSX 10.12 or iOS 10.
Refs #349.
This commit is contained in:
ehlertjd@gmail.com
2016-09-15 16:10:49 -05:00
parent 1206a1e604
commit a542401946

View File

@@ -136,23 +136,11 @@ mg_static_assert(sizeof(void *) >= sizeof(int), "data type size check");
#include <mach/mach_time.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 */
int clock_gettime(int clk_id, struct timespec *t);
int _civet_clock_gettime(int clk_id, struct timespec *t);
int
clock_gettime(int clk_id, struct timespec *t)
_civet_clock_gettime(int clk_id, struct timespec *t)
{
memset(t, 0, sizeof(*t));
if (clk_id == CLOCK_REALTIME) {
@@ -192,7 +180,25 @@ clock_gettime(int clk_id, struct timespec *t)
}
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