/* POSIX clock in all its glory */ int clock_gettime(clockid_t clk_id, struct timespec* tp) { struct timeval ptimeval = { 0 }; int ret = 0; OSTime cosTime; if (tp == NULL) { errno = EFAULT; return -1; } switch (clk_id) { case CLOCK_REALTIME: /* Just wrap gettimeofday. Cheating, I know. */ ret = _gettimeofday_r(NULL, &ptimeval, NULL); if (ret) return -1; tp->tv_sec = ptimeval.tv_sec; tp->tv_nsec = ptimeval.tv_usec * 1000; break; default: errno = EINVAL; return -1; } return 0; }
time_t time (time_t * t) { struct timeval now; if (_gettimeofday_r (_REENT, &now, NULL) < 0) now.tv_sec = (time_t) -1; if (t) *t = now.tv_sec; return now.tv_sec; }