1 #include <time.h> 2 #include <limits.h> 3 clock()4clock_t clock() 5 { 6 struct timespec ts; 7 8 if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)) 9 return -1; 10 11 if (ts.tv_sec > LONG_MAX/1000000 12 || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec) 13 return -1; 14 15 return ts.tv_sec*1000000 + ts.tv_nsec/1000; 16 } 17