rework langinfo code for ABI compat and for use by time code
[musl] / src / time / clock.c
index 2feddb3..c348e39 100644 (file)
@@ -1,9 +1,18 @@
 #include <time.h>
-#include <sys/times.h>
+#include <limits.h>
+
+int __clock_gettime(clockid_t, struct timespec *);
 
-/* this function assumes 100 hz linux and corrects for it */
 clock_t clock()
 {
-       struct tms tms;
-       return (unsigned long)times(&tms)*10000;
+       struct timespec ts;
+
+       if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts))
+               return -1;
+
+       if (ts.tv_sec > LONG_MAX/1000000
+        || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec)
+               return -1;
+
+       return ts.tv_sec*1000000 + ts.tv_nsec/1000;
 }