1*0afa8e06SEd Maste /* 2*0afa8e06SEd Maste * Public domain 3*0afa8e06SEd Maste * sys/time.h compatibility shim 4*0afa8e06SEd Maste */ 5*0afa8e06SEd Maste 6*0afa8e06SEd Maste #if defined(_MSC_VER) && (_MSC_VER >= 1900) 7*0afa8e06SEd Maste #include <../ucrt/time.h> 8*0afa8e06SEd Maste #elif defined(_MSC_VER) && (_MSC_VER < 1900) 9*0afa8e06SEd Maste #include <../include/time.h> 10*0afa8e06SEd Maste #else 11*0afa8e06SEd Maste #include <time.h> 12*0afa8e06SEd Maste #endif 13*0afa8e06SEd Maste 14*0afa8e06SEd Maste #ifndef _COMPAT_TIME_H 15*0afa8e06SEd Maste #define _COMPAT_TIME_H 16*0afa8e06SEd Maste 17*0afa8e06SEd Maste #ifndef CLOCK_MONOTONIC 18*0afa8e06SEd Maste #define CLOCK_MONOTONIC CLOCK_REALTIME 19*0afa8e06SEd Maste #endif 20*0afa8e06SEd Maste 21*0afa8e06SEd Maste #ifndef CLOCK_REALTIME 22*0afa8e06SEd Maste #define CLOCK_REALTIME 0 23*0afa8e06SEd Maste #endif 24*0afa8e06SEd Maste 25*0afa8e06SEd Maste #ifndef HAVE_CLOCK_GETTIME 26*0afa8e06SEd Maste typedef int clockid_t; 27*0afa8e06SEd Maste int clock_gettime(clockid_t, struct timespec *); 28*0afa8e06SEd Maste #endif 29*0afa8e06SEd Maste 30*0afa8e06SEd Maste #ifdef HAVE_TIMESPECSUB 31*0afa8e06SEd Maste #include <sys/time.h> 32*0afa8e06SEd Maste #endif 33*0afa8e06SEd Maste 34*0afa8e06SEd Maste #ifndef HAVE_TIMESPECSUB 35*0afa8e06SEd Maste #define timespecadd(tsp, usp, vsp) \ 36*0afa8e06SEd Maste do { \ 37*0afa8e06SEd Maste (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ 38*0afa8e06SEd Maste (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ 39*0afa8e06SEd Maste if ((vsp)->tv_nsec >= 1000000000L) { \ 40*0afa8e06SEd Maste (vsp)->tv_sec++; \ 41*0afa8e06SEd Maste (vsp)->tv_nsec -= 1000000000L; \ 42*0afa8e06SEd Maste } \ 43*0afa8e06SEd Maste } while (0) 44*0afa8e06SEd Maste 45*0afa8e06SEd Maste #define timespecsub(tsp, usp, vsp) \ 46*0afa8e06SEd Maste do { \ 47*0afa8e06SEd Maste (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ 48*0afa8e06SEd Maste (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ 49*0afa8e06SEd Maste if ((vsp)->tv_nsec < 0) { \ 50*0afa8e06SEd Maste (vsp)->tv_sec--; \ 51*0afa8e06SEd Maste (vsp)->tv_nsec += 1000000000L; \ 52*0afa8e06SEd Maste } \ 53*0afa8e06SEd Maste } while (0) 54*0afa8e06SEd Maste 55*0afa8e06SEd Maste #define timespeccmp(tsp, usp, cmp) \ 56*0afa8e06SEd Maste (((tsp)->tv_sec == (usp)->tv_sec) ? \ 57*0afa8e06SEd Maste ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ 58*0afa8e06SEd Maste ((tsp)->tv_sec cmp (usp)->tv_sec)) 59*0afa8e06SEd Maste #endif 60*0afa8e06SEd Maste 61*0afa8e06SEd Maste #endif /* _COMPAT_TIME_H */ 62