@@ -33,12 +33,34 @@ struct timespec _al_unix_initial_time;
33
33
34
34
35
35
36
+ /* clock_gettime() doesn't exist in MacOSX versions < 10.12. Use
37
+ * gettimeofday() if building for MacOSX and targeting version < 10.12.
38
+ */
39
+ #if defined(ALLEGRO_MACOSX ) && MAC_OS_X_VERSION_MIN_REQUIRED < 101200
40
+ #include <mach/mach_time.h>
41
+ int _internal_clock_gettime (clockid_t clock_id , struct timespec * t )
42
+ {
43
+ struct timeval now ;
44
+
45
+ (void )clock_id ;
46
+ gettimeofday (& now , NULL );
47
+ t -> tv_sec = now .tv_sec ;
48
+ t -> tv_nsec = now .tv_usec * 1000 ;
49
+ return 0 ;
50
+ }
51
+ #define _al_clock_gettime _internal_clock_gettime
52
+ #else
53
+ #define _al_clock_gettime clock_gettime
54
+ #endif
55
+
56
+
57
+
36
58
/* _al_unix_init_time:
37
59
* Called by the system driver to mark the beginning of time.
38
60
*/
39
61
void _al_unix_init_time (void )
40
62
{
41
- clock_gettime (CLOCK_REALTIME , & _al_unix_initial_time );
63
+ _al_clock_gettime (CLOCK_REALTIME , & _al_unix_initial_time );
42
64
}
43
65
44
66
@@ -48,7 +70,7 @@ double _al_unix_get_time(void)
48
70
struct timespec now ;
49
71
double time ;
50
72
51
- clock_gettime (CLOCK_REALTIME , & now );
73
+ _al_clock_gettime (CLOCK_REALTIME , & now );
52
74
time = (double ) (now .tv_sec - _al_unix_initial_time .tv_sec )
53
75
+ (double ) (now .tv_nsec - _al_unix_initial_time .tv_nsec ) * 1.0e-9 ;
54
76
return time ;
@@ -79,7 +101,7 @@ void _al_unix_init_timeout(ALLEGRO_TIMEOUT *timeout, double seconds)
79
101
80
102
ASSERT (ut );
81
103
82
- clock_gettime (CLOCK_REALTIME , & now );
104
+ _al_clock_gettime (CLOCK_REALTIME , & now );
83
105
84
106
if (seconds <= 0.0 ) {
85
107
ut -> abstime .tv_sec = now .tv_sec ;
0 commit comments