osxcross/patches/compiler-rt_clock-gettime.patch

31 lines
1.0 KiB
Diff
Raw Normal View History

diff -crB --new-file /home/thomas/tmp/compiler-rt/include/time.h compiler-rt/include/time.h
*** /home/thomas/tmp/compiler-rt/include/time.h 1970-01-01 01:00:00.000000000 +0100
--- compiler-rt/include/time.h 2019-06-01 15:42:13.006343150 +0200
***************
*** 0 ****
--- 1,24 ----
+ #ifndef __TIME_H_INCLUDE_HACK__
+ #define __TIME_H_INCLUDE_HACK__
+ #ifdef __MACH__
+ /* https://stackoverflow.com/a/17112198/1392778 */
+ #include_next <time.h>
+ #include <mach/mach_time.h>
+ #define CLOCK_REALTIME 0
+ #define CLOCK_MONOTONIC 0
+ typedef int clockid_t;
+ static int clock_gettime(clockid_t clk_id, struct timespec *t){
+ mach_timebase_info_data_t timebase;
+ mach_timebase_info(&timebase);
+ uint64_t time;
+ time = mach_absolute_time();
+ double nseconds = ((double)time * (double)timebase.numer)/((double)timebase.denom);
+ double seconds = ((double)time * (double)timebase.numer)/((double)timebase.denom * 1e9);
+ t->tv_sec = seconds;
+ t->tv_nsec = nseconds;
+ return 0;
+ }
+ #else
+ #include_next <time.h>
+ #endif
+ #endif