const correctness on function pointer
[musl] / src / time / clock_gettime.c
1 #include <time.h>
2 #include <errno.h>
3 #include <stdint.h>
4 #include "syscall.h"
5 #include "libc.h"
6
7 int __vdso_clock_gettime(clockid_t, struct timespec *) __attribute__((weak));
8 static int (*const cgt)(clockid_t, struct timespec *) = __vdso_clock_gettime;
9
10 int __clock_gettime(clockid_t clk, struct timespec *ts)
11 {
12         int r;
13         if (cgt) return cgt(clk, ts);
14         r = __syscall(SYS_clock_gettime, clk, ts);
15         if (!r) return r;
16         if (r == -ENOSYS) {
17                 if (clk == CLOCK_REALTIME) {
18                         __syscall(SYS_gettimeofday, clk, ts, 0);
19                         ts->tv_nsec = (int)ts->tv_nsec * 1000;
20                         return 0;
21                 }
22                 r = -EINVAL;
23         }
24         errno = -r;
25         return -1;
26 }
27
28 weak_alias(__clock_gettime, clock_gettime);