diff options
author | Brent Cook <busterb@gmail.com> | 2018-03-22 20:50:24 -0500 |
---|---|---|
committer | Brent Cook <busterb@gmail.com> | 2018-03-22 21:04:43 -0500 |
commit | 987aa6a084312be8501bdda42b0e5aab3b84d52a (patch) | |
tree | 9c3cf68f0ca3cb172d5d2238563c979b29543d08 /apps/openssl/compat | |
parent | 78600e9bec2b52f0f8a0f7ce376f3783999bb824 (diff) | |
download | portable-987aa6a084312be8501bdda42b0e5aab3b84d52a.tar.gz portable-987aa6a084312be8501bdda42b0e5aab3b84d52a.tar.bz2 portable-987aa6a084312be8501bdda42b0e5aab3b84d52a.zip |
add clock_gettime for macos 10.11 and earlier
Diffstat (limited to 'apps/openssl/compat')
-rw-r--r-- | apps/openssl/compat/clock_gettime_osx.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 | |||
7 | int | ||
8 | clock_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 | } | ||