From 987aa6a084312be8501bdda42b0e5aab3b84d52a Mon Sep 17 00:00:00 2001 From: Brent Cook Date: Thu, 22 Mar 2018 20:50:24 -0500 Subject: add clock_gettime for macos 10.11 and earlier --- apps/openssl/Makefile.am | 6 ++++++ apps/openssl/compat/clock_gettime_osx.c | 26 ++++++++++++++++++++++++++ include/compat/sys/time.h | 4 ---- include/compat/time.h | 13 +++++++++++++ m4/check-libc.m4 | 2 ++ 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 apps/openssl/compat/clock_gettime_osx.c diff --git a/apps/openssl/Makefile.am b/apps/openssl/Makefile.am index 9b9eb10..f100adb 100644 --- a/apps/openssl/Makefile.am +++ b/apps/openssl/Makefile.am @@ -74,6 +74,12 @@ openssl_SOURCES += compat/poll_win.c endif endif +if !HAVE_CLOCK_GETTIME +if HOST_DARWIN +openssl_SOURCES += compat/clock_gettime_osx.c +endif +endif + if !HAVE_STRTONUM openssl_SOURCES += compat/strtonum.c endif diff --git a/apps/openssl/compat/clock_gettime_osx.c b/apps/openssl/compat/clock_gettime_osx.c new file mode 100644 index 0000000..e0a5f59 --- /dev/null +++ b/apps/openssl/compat/clock_gettime_osx.c @@ -0,0 +1,26 @@ +#include + +#include +#define ORWL_NANO (+1.0E-9) +#define ORWL_GIGA UINT64_C(1000000000) + +int +clock_gettime(clock_id_t clock_id, struct timespec *tp) +{ + static double orwl_timebase = 0.0; + static uint64_t orwl_timestart = 0; + + if (!orwl_timestart) { + mach_timebase_info_data_t tb = { 0 }; + mach_timebase_info(&tb); + orwl_timebase = tb.numer; + orwl_timebase /= tb.denom; + orwl_timestart = mach_absolute_time(); + } + + double diff = (mach_absolute_time() - orwl_timestart) * orwl_timebase; + tp->tv_sec = diff * ORWL_NANO; + tp->tv_nsec = diff - (tp->tv_sec * ORWL_GIGA); + + return 0; +} diff --git a/include/compat/sys/time.h b/include/compat/sys/time.h index 3d31985..76428c1 100644 --- a/include/compat/sys/time.h +++ b/include/compat/sys/time.h @@ -13,10 +13,6 @@ int gettimeofday(struct timeval *tp, void *tzp); #include_next #endif -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC CLOCK_REALTIME -#endif - #ifndef timersub #define timersub(tvp, uvp, vvp) \ do { \ diff --git a/include/compat/time.h b/include/compat/time.h index df65530..d43dfcb 100644 --- a/include/compat/time.h +++ b/include/compat/time.h @@ -22,6 +22,19 @@ struct tm *__gmtime_r(const time_t * t, struct tm * tm); time_t timegm(struct tm *tm); #endif +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC CLOCK_REALTIME +#endif + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME 0 +#endif + +#ifndef HAVE_CLOCK_GETTIME +int +clock_gettime(clockid_t clock_id, struct timespec *tp); +#endif + #ifndef timespecsub #define timespecsub(tsp, usp, vsp) \ do { \ diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index cacdd17..df0266a 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 @@ -131,6 +131,8 @@ AC_SEARCH_LIBS([clock_gettime],[rt posix4]) AC_CHECK_FUNC([clock_gettime]) AC_SEARCH_LIBS([dl_iterate_phdr],[dl]) AC_CHECK_FUNC([dl_iterate_phdr]) + +AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes]) ]) AC_DEFUN([CHECK_VA_COPY], [ -- cgit v1.2.3-55-g6feb