1 #include <time.h> 2 #include <sys/time.h> 3 gettimeofday(struct timeval * restrict tv,void * restrict tz)4int gettimeofday(struct timeval *restrict tv, void *restrict tz) 5 { 6 struct timespec ts; 7 if (!tv) return 0; 8 clock_gettime(CLOCK_REALTIME, &ts); 9 tv->tv_sec = ts.tv_sec; 10 tv->tv_usec = (int)ts.tv_nsec / 1000; 11 return 0; 12 } 13