Merge "Add file_offset parameter to android_extinfo"
diff --git a/libc/bionic/clock.cpp b/libc/bionic/clock.cpp
index a2636c6..053e9e7 100644
--- a/libc/bionic/clock.cpp
+++ b/libc/bionic/clock.cpp
@@ -30,12 +30,13 @@
#include <sys/sysconf.h>
#include <sys/times.h>
+#include "private/bionic_constants.h"
+
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock.html
clock_t clock() {
- tms t;
- times(&t);
- // Although times(2) and clock(3) both use the type clock_t, the units are
- // different. For times(2) it's pure clock ticks, but for clock(3) the unit
- // is CLOCKS_PER_SEC, so we need to scale appropriately.
- return (t.tms_utime + t.tms_stime) * (CLOCKS_PER_SEC / sysconf(_SC_CLK_TCK));
+ timespec ts;
+ if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts) == -1) {
+ return -1;
+ }
+ return (ts.tv_sec * CLOCKS_PER_SEC) + (ts.tv_nsec / (NS_PER_S / CLOCKS_PER_SEC));
}
diff --git a/libc/include/string.h b/libc/include/string.h
index b0643af..fb24808 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -115,12 +115,7 @@
__BIONIC_FORTIFY_INLINE
void* memcpy(void* __restrict dest, const void* __restrict src, size_t copy_amount) {
- char *d = (char *) dest;
- const char *s = (const char *) src;
- size_t s_len = __bos0(s);
- size_t d_len = __bos0(d);
-
- return __builtin___memcpy_chk(dest, src, copy_amount, d_len);
+ return __builtin___memcpy_chk(dest, src, copy_amount, __bos0(dest));
}
__BIONIC_FORTIFY_INLINE
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index c631b6a..d2fec9a 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -404,3 +404,11 @@
ASSERT_EQ(0, ts2.tv_sec);
ASSERT_LT(ts2.tv_nsec, 1000000);
}
+
+TEST(time, clock) {
+ // clock(3) is hard to test, but a 1s sleep should cost less than 1ms.
+ clock_t t0 = clock();
+ sleep(1);
+ clock_t t1 = clock();
+ ASSERT_LT(t1 - t0, CLOCKS_PER_SEC / 1000);
+}