initial commit
[glibc.git] / sysdeps / unix / bsd / bsd4.4 / kfreebsd / fbtl / clock_getres.c
1 /* Copyright (C) 2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <stdint.h>
20 #include <time.h>
21 #include <sys/time.h>
22 #include <libc-internal.h>
23 #include <ldsodefs.h>
24 #include <sysdep.h>
25
26 int __syscall_clock_getres(clockid_t clock_id, struct timespec *tp);
27 libc_hidden_proto (__syscall_clock_getres)
28
29 int __syscall_clock_gettime(clockid_t clock_id, struct timespec *tp);
30 libc_hidden_proto (__syscall_clock_gettime)
31
32 /* Get resolution of clock. */
33 int
34 __clock_getres (clockid_t clock_id, struct timespec *tp)
35 {
36 /* we could try to provide fallback
37 via ??? for CLOCK_REALTIME
38 via HP_TIMING for CLOCK_PROCESS_CPUTIME_ID,
39 CLOCK_THREAD_CPUTIME_ID and related timers
40
41 for now just pass it to kernel
42 */
43 /* the negative clock_id means a CPU-timer, the resolution is same for all of them
44 the kernel returns resolution regardless whether the timer is accessible,
45 but POSIX/testsuite expects EINVAL
46 */
47
48 if (clock_id < 0)
49 {
50 int rv;
51 /* we reuse user provided struct timespec */
52 rv = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp);
53 if (rv != 0)
54 return rv;
55 /* valid, now really get the resolution */
56 }
57
58 return INLINE_SYSCALL (clock_getres, 2, clock_id, tp);
59 }
60 strong_alias (__clock_getres, clock_getres)