4 #include <mach/mach_time.h>
8 void *memrchr(
const void *s,
int c,
size_t n){
10 for(
size_t i = n; i > 0; i--){
12 return (
void*)(cs + i - 1);
19 static unsigned long factor = 0;
22 mach_timebase_info_data_t info;
23 mach_timebase_info(&info);
24 return factor = (double)info.numer / (
double)info.denom;
27 int clock_gettime(clockid_t clk_id,
struct timespec *tp){
28 if(clk_id != CLOCK_MONOTONIC){
32 unsigned long factor = getfactor();
33 unsigned long nsec = mach_absolute_time() * factor;
34 tp->tv_sec = nsec / 1000000000;
35 tp->tv_nsec = nsec % 1000000000;
39 int clock_nanosleep(clockid_t clock_id,
int flags,
const struct timespec *rqtp,
struct timespec *rmtp){
40 if(clock_id != CLOCK_MONOTONIC)
42 if(flags == TIMER_ABSTIME){
45 struct timespec curtime, realtime;
46 clock_gettime(clock_id, &curtime);
50 realtime.tv_sec = rqtp->tv_sec - curtime.tv_sec;
51 realtime.tv_nsec = rqtp->tv_nsec - curtime.tv_nsec;
52 if(realtime.tv_nsec < 0){
55 realtime.tv_nsec += 1000000000;
57 int res = nanosleep(&realtime, 0);
63 int res = nanosleep(rqtp, rmtp);
#define timespec_ge(left, right)