kopia lustrzana https://github.com/Hamlib/Hamlib
Change MacOS detection logic for clock_gettime to hopefully cover all flavors
rodzic
9695828b19
commit
30eca94210
74
src/misc.c
74
src/misc.c
|
@ -57,48 +57,64 @@
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#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>
|
# include <mach/mach_time.h>
|
||||||
# ifndef __clockid_t_defined
|
# ifndef __clockid_t_defined
|
||||||
typedef enum clockid_t;
|
typedef int clockid_t;
|
||||||
#define __clockid_t_defined 1
|
#define __clockid_t_defined 1
|
||||||
# endif /* __clockid_t_defined */
|
# endif /* __clockid_t_defined */
|
||||||
|
|
||||||
# define CLOCK_REALTIME 0
|
# define CLOCK_REALTIME 0
|
||||||
# define CLOCK_MONOTONIC 6
|
# 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) {
|
if (clock_id == CLOCK_REALTIME)
|
||||||
struct timeval t;
|
{
|
||||||
if (gettimeofday(&t, NULL) != 0)
|
struct timeval t;
|
||||||
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;
|
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 // !HAVE_CLOCK_GETTIME
|
||||||
|
|
||||||
#endif // __APPLE__
|
#endif // __APPLE__
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Convert from binary to 4-bit BCD digits, little-endian
|
* \brief Convert from binary to 4-bit BCD digits, little-endian
|
||||||
* \param bcd_data
|
* \param bcd_data
|
||||||
|
|
Ładowanie…
Reference in New Issue