aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2018-03-22 20:50:24 -0500
committerBrent Cook <busterb@gmail.com>2018-03-22 21:04:43 -0500
commit987aa6a084312be8501bdda42b0e5aab3b84d52a (patch)
tree9c3cf68f0ca3cb172d5d2238563c979b29543d08
parent78600e9bec2b52f0f8a0f7ce376f3783999bb824 (diff)
downloadportable-987aa6a084312be8501bdda42b0e5aab3b84d52a.tar.gz
portable-987aa6a084312be8501bdda42b0e5aab3b84d52a.tar.bz2
portable-987aa6a084312be8501bdda42b0e5aab3b84d52a.zip
add clock_gettime for macos 10.11 and earlier
-rw-r--r--apps/openssl/Makefile.am6
-rw-r--r--apps/openssl/compat/clock_gettime_osx.c26
-rw-r--r--include/compat/sys/time.h4
-rw-r--r--include/compat/time.h13
-rw-r--r--m4/check-libc.m42
5 files changed, 47 insertions, 4 deletions
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
74endif 74endif
75endif 75endif
76 76
77if !HAVE_CLOCK_GETTIME
78if HOST_DARWIN
79openssl_SOURCES += compat/clock_gettime_osx.c
80endif
81endif
82
77if !HAVE_STRTONUM 83if !HAVE_STRTONUM
78openssl_SOURCES += compat/strtonum.c 84openssl_SOURCES += compat/strtonum.c
79endif 85endif
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 @@
1#include <time.h>
2
3#include <mach/mach_time.h>
4#define ORWL_NANO (+1.0E-9)
5#define ORWL_GIGA UINT64_C(1000000000)
6
7int
8clock_gettime(clock_id_t clock_id, struct timespec *tp)
9{
10 static double orwl_timebase = 0.0;
11 static uint64_t orwl_timestart = 0;
12
13 if (!orwl_timestart) {
14 mach_timebase_info_data_t tb = { 0 };
15 mach_timebase_info(&tb);
16 orwl_timebase = tb.numer;
17 orwl_timebase /= tb.denom;
18 orwl_timestart = mach_absolute_time();
19 }
20
21 double diff = (mach_absolute_time() - orwl_timestart) * orwl_timebase;
22 tp->tv_sec = diff * ORWL_NANO;
23 tp->tv_nsec = diff - (tp->tv_sec * ORWL_GIGA);
24
25 return 0;
26}
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);
13#include_next <sys/time.h> 13#include_next <sys/time.h>
14#endif 14#endif
15 15
16#ifndef CLOCK_MONOTONIC
17#define CLOCK_MONOTONIC CLOCK_REALTIME
18#endif
19
20#ifndef timersub 16#ifndef timersub
21#define timersub(tvp, uvp, vvp) \ 17#define timersub(tvp, uvp, vvp) \
22 do { \ 18 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);
22time_t timegm(struct tm *tm); 22time_t timegm(struct tm *tm);
23#endif 23#endif
24 24
25#ifndef CLOCK_MONOTONIC
26#define CLOCK_MONOTONIC CLOCK_REALTIME
27#endif
28
29#ifndef CLOCK_REALTIME
30#define CLOCK_REALTIME 0
31#endif
32
33#ifndef HAVE_CLOCK_GETTIME
34int
35clock_gettime(clockid_t clock_id, struct timespec *tp);
36#endif
37
25#ifndef timespecsub 38#ifndef timespecsub
26#define timespecsub(tsp, usp, vsp) \ 39#define timespecsub(tsp, usp, vsp) \
27 do { \ 40 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])
131AC_CHECK_FUNC([clock_gettime]) 131AC_CHECK_FUNC([clock_gettime])
132AC_SEARCH_LIBS([dl_iterate_phdr],[dl]) 132AC_SEARCH_LIBS([dl_iterate_phdr],[dl])
133AC_CHECK_FUNC([dl_iterate_phdr]) 133AC_CHECK_FUNC([dl_iterate_phdr])
134
135AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes])
134]) 136])
135 137
136AC_DEFUN([CHECK_VA_COPY], [ 138AC_DEFUN([CHECK_VA_COPY], [