X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Ftime%2Fclock_gettime.c;h=9fef54a497b980e1ea121b584e1ed0c6fe83e044;hp=6b880a068ef27c5efb9be42392b096a3a1e1a4b0;hb=e91c375fd027a485bd7415afbaf059d429e11e11;hpb=4b1244a0bfec55bc4cad91ff157997929f106215 diff --git a/src/time/clock_gettime.c b/src/time/clock_gettime.c index 6b880a06..9fef54a4 100644 --- a/src/time/clock_gettime.c +++ b/src/time/clock_gettime.c @@ -1,8 +1,29 @@ -#define SYSCALL_RETURN_ERRNO #include +#include +#include #include "syscall.h" +#include "libc.h" -int clock_gettime(clockid_t clk, struct timespec *ts) +int __vdso_clock_gettime(clockid_t, struct timespec *) __attribute__((weak)); +static int (*cgt)(clockid_t, struct timespec *) = __vdso_clock_gettime; + +int __clock_gettime(clockid_t clk, struct timespec *ts) { - return syscall2(__NR_clock_gettime, clk, (long)ts); + int r; + if (cgt) return cgt(clk, ts); + r = __syscall(SYS_clock_gettime, clk, ts); + if (!r) return r; + if (r == -ENOSYS) { + cgt = 0; + if (clk == CLOCK_REALTIME) { + __syscall(SYS_gettimeofday, clk, ts, 0); + ts->tv_nsec = (int)ts->tv_nsec * 1000; + return 0; + } + r = -EINVAL; + } + errno = -r; + return -1; } + +weak_alias(__clock_gettime, clock_gettime);