diff options
author | Brent Cook <bcook@openbsd.org> | 2018-03-23 18:15:50 -0500 |
---|---|---|
committer | Brent Cook <bcook@openbsd.org> | 2018-03-23 18:15:50 -0500 |
commit | 31a66e1c5bc4fb09eac7b425445ef405f88e55af (patch) | |
tree | f875b56b8e799a675c15aba830c1ba9e127728a3 | |
parent | 28041ddc32bb8cb3cc1e1b5bed0b73402bf59485 (diff) | |
parent | 31c98c2969f70b2db3e866352ec027f7b965c406 (diff) | |
download | portable-31a66e1c5bc4fb09eac7b425445ef405f88e55af.tar.gz portable-31a66e1c5bc4fb09eac7b425445ef405f88e55af.tar.bz2 portable-31a66e1c5bc4fb09eac7b425445ef405f88e55af.zip |
Land #412, fix builds for macos 10.11
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | apps/openssl/Makefile.am | 6 | ||||
-rw-r--r-- | apps/openssl/compat/clock_gettime_osx.c | 26 | ||||
-rw-r--r-- | include/compat/sys/time.h | 4 | ||||
-rw-r--r-- | include/compat/time.h | 18 | ||||
-rw-r--r-- | m4/check-libc.m4 | 10 |
6 files changed, 62 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index a67405a..03c87a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -283,6 +283,12 @@ endif() | |||
283 | if(WIN32) | 283 | if(WIN32) |
284 | set(OPENSSL_LIBS ${OPENSSL_LIBS} ws2_32) | 284 | set(OPENSSL_LIBS ${OPENSSL_LIBS} ws2_32) |
285 | endif() | 285 | endif() |
286 | |||
287 | check_function_exists(clock_gettime HAVE_CLOCK_GETTIME) | ||
288 | if(HAVE_CLOCK_GETTIME) | ||
289 | add_definitions(-DHAVE_CLOCK_GETTIME) | ||
290 | endif() | ||
291 | |||
286 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") | 292 | if(CMAKE_SYSTEM_NAME MATCHES "Linux") |
287 | check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) | 293 | check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) |
288 | if (HAVE_CLOCK_GETTIME) | 294 | if (HAVE_CLOCK_GETTIME) |
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 | |||
74 | endif | 74 | endif |
75 | endif | 75 | endif |
76 | 76 | ||
77 | if !HAVE_CLOCK_GETTIME | ||
78 | if HOST_DARWIN | ||
79 | openssl_SOURCES += compat/clock_gettime_osx.c | ||
80 | endif | ||
81 | endif | ||
82 | |||
77 | if !HAVE_STRTONUM | 83 | if !HAVE_STRTONUM |
78 | openssl_SOURCES += compat/strtonum.c | 84 | openssl_SOURCES += compat/strtonum.c |
79 | endif | 85 | 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..5545187 --- /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 | |||
7 | int | ||
8 | clock_gettime(clockid_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..dc460ef 100644 --- a/include/compat/time.h +++ b/include/compat/time.h | |||
@@ -13,6 +13,9 @@ | |||
13 | #include_next <time.h> | 13 | #include_next <time.h> |
14 | #endif | 14 | #endif |
15 | 15 | ||
16 | #ifndef LIBCRYPTOCOMPAT_TIME_H | ||
17 | #define LIBCRYPTOCOMPAT_TIME_H | ||
18 | |||
16 | #ifdef _WIN32 | 19 | #ifdef _WIN32 |
17 | struct tm *__gmtime_r(const time_t * t, struct tm * tm); | 20 | struct tm *__gmtime_r(const time_t * t, struct tm * tm); |
18 | #define gmtime_r(tp, tm) __gmtime_r(tp, tm) | 21 | #define gmtime_r(tp, tm) __gmtime_r(tp, tm) |
@@ -22,6 +25,19 @@ struct tm *__gmtime_r(const time_t * t, struct tm * tm); | |||
22 | time_t timegm(struct tm *tm); | 25 | time_t timegm(struct tm *tm); |
23 | #endif | 26 | #endif |
24 | 27 | ||
28 | #ifndef CLOCK_MONOTONIC | ||
29 | #define CLOCK_MONOTONIC CLOCK_REALTIME | ||
30 | #endif | ||
31 | |||
32 | #ifndef CLOCK_REALTIME | ||
33 | #define CLOCK_REALTIME 0 | ||
34 | #endif | ||
35 | |||
36 | #ifndef HAVE_CLOCK_GETTIME | ||
37 | typedef int clockid_t; | ||
38 | int clock_gettime(clockid_t clock_id, struct timespec *tp); | ||
39 | #endif | ||
40 | |||
25 | #ifndef timespecsub | 41 | #ifndef timespecsub |
26 | #define timespecsub(tsp, usp, vsp) \ | 42 | #define timespecsub(tsp, usp, vsp) \ |
27 | do { \ | 43 | do { \ |
@@ -33,3 +49,5 @@ time_t timegm(struct tm *tm); | |||
33 | } \ | 49 | } \ |
34 | } while (0) | 50 | } while (0) |
35 | #endif | 51 | #endif |
52 | |||
53 | #endif | ||
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 index cacdd17..1fff77e 100644 --- a/m4/check-libc.m4 +++ b/m4/check-libc.m4 | |||
@@ -126,11 +126,13 @@ AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], | |||
126 | -a "x$ac_cv_func_arc4random_buf" = xyes]) | 126 | -a "x$ac_cv_func_arc4random_buf" = xyes]) |
127 | 127 | ||
128 | # Check for getentropy fallback dependencies | 128 | # Check for getentropy fallback dependencies |
129 | AC_CHECK_FUNC([getauxval]) | 129 | AC_CHECK_FUNCS([getauxval]) |
130 | AC_SEARCH_LIBS([clock_gettime],[rt posix4]) | ||
131 | AC_CHECK_FUNC([clock_gettime]) | ||
132 | AC_SEARCH_LIBS([dl_iterate_phdr],[dl]) | 130 | AC_SEARCH_LIBS([dl_iterate_phdr],[dl]) |
133 | AC_CHECK_FUNC([dl_iterate_phdr]) | 131 | AC_CHECK_FUNCS([dl_iterate_phdr]) |
132 | |||
133 | AC_SEARCH_LIBS([clock_gettime],[rt posix4]) | ||
134 | AC_CHECK_FUNCS([clock_gettime]) | ||
135 | AM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test "x$ac_cv_func_clock_gettime" = xyes]) | ||
134 | ]) | 136 | ]) |
135 | 137 | ||
136 | AC_DEFUN([CHECK_VA_COPY], [ | 138 | AC_DEFUN([CHECK_VA_COPY], [ |