Add CLOCK_MONOTONIC and timersub for the OS that does not have them

This commit is contained in:
kinichiro 2017-12-25 16:30:49 +09:00
parent 7b6953e9a9
commit 965a89108e

View File

@ -13,4 +13,20 @@ int gettimeofday(struct timeval *tp, void *tzp);
#include_next <sys/time.h> #include_next <sys/time.h>
#endif #endif
#ifndef CLOCK_MONOTONIC
#define CLOCK_MONOTONIC CLOCK_REALTIME
#endif
#ifndef timersub
#define timersub(tvp, uvp, vvp) \
do { \
(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
if ((vvp)->tv_usec < 0) { \
(vvp)->tv_sec--; \
(vvp)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif #endif