diff --git a/src/misc.c b/src/misc.c index 3206fe67b..e5a0a6e76 100644 --- a/src/misc.c +++ b/src/misc.c @@ -57,48 +57,64 @@ #include "misc.h" #include "serial.h" #include "network.h" + #ifdef __APPLE__ -#ifndef HAVE_CLOCK_GETTIME +#include + +#if AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + +#else # include -# ifndef __clockid_t_defined - typedef enum clockid_t; - #define __clockid_t_defined 1 -# endif /* __clockid_t_defined */ +# ifndef __clockid_t_defined +typedef int clockid_t; +#define __clockid_t_defined 1 +# endif /* __clockid_t_defined */ -# define CLOCK_REALTIME 0 -# define CLOCK_MONOTONIC 6 +# define CLOCK_REALTIME 0 +# define CLOCK_MONOTONIC 1 -int clock_gettime(clockid_t clock_id, struct timespec* tp) +int clock_gettime(clockid_t clock_id, struct timespec *tp) { - if (clock_id == CLOCK_REALTIME) { - struct timeval t; - if (gettimeofday(&t, NULL) != 0) - return -1; - tp->tv_sec = t.tv_sec; - tp->tv_nsec = t.tv_usec * 1000; - } - else if (clock_id == CLOCK_MONOTONIC) { - static mach_timebase_info_data_t info = { 0, 0 }; - if (info.denom == 0) - mach_timebase_info(&info); - uint64_t t = mach_absolute_time() * info.numer / info.denom; - tp->tv_sec = t / 1000000000; - tp->tv_nsec = t % 1000000000; - } - else { - errno = EINVAL; - return -1; - } + if (clock_id == CLOCK_REALTIME) + { + struct timeval t; - return 0; + if (gettimeofday(&t, NULL) != 0) + { + return -1; + } + + tp->tv_sec = t.tv_sec; + tp->tv_nsec = t.tv_usec * 1000; + } + else if (clock_id == CLOCK_MONOTONIC) + { + static mach_timebase_info_data_t info = { 0, 0 }; + + if (info.denom == 0) + { + mach_timebase_info(&info); + } + + uint64_t t = mach_absolute_time() * info.numer / info.denom; + tp->tv_sec = t / 1000000000; + tp->tv_nsec = t % 1000000000; + } + else + { + errno = EINVAL; + return -1; + } + + return 0; } + #endif // !HAVE_CLOCK_GETTIME #endif // __APPLE__ - /** * \brief Convert from binary to 4-bit BCD digits, little-endian * \param bcd_data