[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. f2b7893a2b81c00e7a999
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: Michael B. <mdb...@us...> - 2021-01-27 17:01:23
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via f2b7893a2b81c00e7a9998b376b846a34bab1205 (commit) via 30eca94210ece61603d2d09d88632125c66072b4 (commit) from 9695828b1994245d0ed9d2cb756ff9170209fc14 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit f2b7893a2b81c00e7a9998b376b846a34bab1205 Author: Michael Black W9MDB <mdb...@ya...> Date: Wed Jan 27 11:00:58 2021 -0600 Another attempt to get clock_gettime compiling for all Mac flavors diff --git a/src/misc.c b/src/misc.c index e5a0a6e7..eccb7ba1 100644 --- a/src/misc.c +++ b/src/misc.c @@ -60,22 +60,23 @@ #ifdef __APPLE__ -#include <AvailabilityMacros.h> +#include <time.h> -#if AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER +#if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC) +// +// MacOS < 10.12 does not have clock_gettime +// +// Contribution from github user "ra1nb0w" +// -#else - -# include <mach/mach_time.h> -# ifndef __clockid_t_defined +#define CLOCK_REALTIME 0 +#define CLOCK_MONOTONIC 6 typedef int clockid_t; -#define __clockid_t_defined 1 -# endif /* __clockid_t_defined */ -# define CLOCK_REALTIME 0 -# define CLOCK_MONOTONIC 1 +#include <sys/time.h> +#include <mach/mach_time.h> -int clock_gettime(clockid_t clock_id, struct timespec *tp) +static int clock_gettime(clockid_t clock_id, struct timespec *tp) { if (clock_id == CLOCK_REALTIME) { commit 30eca94210ece61603d2d09d88632125c66072b4 Author: Michael Black W9MDB <mdb...@ya...> Date: Tue Jan 26 15:05:43 2021 -0600 Change MacOS detection logic for clock_gettime to hopefully cover all flavors diff --git a/src/misc.c b/src/misc.c index 3206fe67..e5a0a6e7 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 <AvailabilityMacros.h> + +#if AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + +#else # include <mach/mach_time.h> -# ifndef __clockid_t_defined - typedef enum clockid_t; - #define __clockid_t_defined 1 -# endif /* __clockid_t_defined */ - -# define CLOCK_REALTIME 0 -# define CLOCK_MONOTONIC 6 - -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; - } - - return 0; +# ifndef __clockid_t_defined +typedef int clockid_t; +#define __clockid_t_defined 1 +# endif /* __clockid_t_defined */ + +# define CLOCK_REALTIME 0 +# define CLOCK_MONOTONIC 1 + +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; + } + + return 0; } + #endif // !HAVE_CLOCK_GETTIME #endif // __APPLE__ - /** * \brief Convert from binary to 4-bit BCD digits, little-endian * \param bcd_data ----------------------------------------------------------------------- Summary of changes: src/misc.c | 87 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 35 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |