Chromium Code Reviews

Unified Diff: fusl/src/time/clock.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « fusl/src/time/asctime_r.c ('k') | fusl/src/time/clock_getcpuclockid.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/time/clock.c
diff --git a/fusl/src/time/clock.c b/fusl/src/time/clock.c
new file mode 100644
index 0000000000000000000000000000000000000000..c348e39836caec86425652d6e0e3259ff9c05a2c
--- /dev/null
+++ b/fusl/src/time/clock.c
@@ -0,0 +1,18 @@
+#include <time.h>
+#include <limits.h>
+
+int __clock_gettime(clockid_t, struct timespec *);
+
+clock_t clock()
+{
+ 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;
+}
« no previous file with comments | « fusl/src/time/asctime_r.c ('k') | fusl/src/time/clock_getcpuclockid.c » ('j') | no next file with comments »

Powered by Google App Engine