summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2019-07-28 22:53:10 -0400
committerRich Felker <dalias@aerifal.cx>2019-07-29 12:31:02 -0400
commit244858553e7eaacd135de5c1cdb49489796b6d02 (patch)
tree1a0c5c9025086c02c9bfaa75416a1954f4549cf4 /src
parenta02bd52864a21b46206eaf67e1e7fb53834b594a (diff)
downloadmusl-244858553e7eaacd135de5c1cdb49489796b6d02.tar.gz
clock_getres: don't assume time_t is 32-bit on 32-bit archs
the time64 syscall for this is not necessary or useful, since clock resolution is generally better than 68-year granularity. if there's a 32-bit syscall, use it and expand the result into timespec; otherwise there is only one syscall and it does the right thing to store to timespec directly. on 64-bit archs, there is no change to the code after preprocessing.
Diffstat (limited to 'src')
-rw-r--r--src/time/clock_getres.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/time/clock_getres.c b/src/time/clock_getres.c
index 36a0d695..f0f41cf9 100644
--- a/src/time/clock_getres.c
+++ b/src/time/clock_getres.c
@@ -3,5 +3,19 @@
int clock_getres(clockid_t clk, struct timespec *ts)
{
+#ifdef SYS_clock_getres_time64
+ /* On a 32-bit arch, use the old syscall if it exists. */
+ if (SYS_clock_getres != SYS_clock_getres_time64) {
+ long ts32[2];
+ int r = __syscall(SYS_clock_getres, clk, ts32);
+ if (!r) {
+ ts->tv_sec = ts32[0];
+ ts->tv_nsec = ts32[1];
+ }
+ return __syscall_ret(r);
+ }
+#endif
+ /* If reaching this point, it's a 64-bit arch or time64-only
+ * 32-bit arch and we can get result directly into timespec. */
return syscall(SYS_clock_getres, clk, ts);
}