1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If
17 not, see <http://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <stdlib.h>
21 #include <time.h>
22 #include <sysdep.h>
23 #include <bits/kernel-features.h>
24 #include "kernel-posix-timers.h"
25
26 #if defined(__UCLIBC_USE_TIME64__)
27 #include "internal/time64_helpers.h"
28 #endif
29
30 #if defined(__NR_timer_settime) || defined(__NR_timer_settime64)
31 # ifndef __ASSUME_POSIX_TIMERS
32 static int compat_timer_settime (timer_t timerid, int flags,
33 const struct itimerspec *value,
34 struct itimerspec *ovalue);
35 # define timer_settime static compat_timer_settime
36 # include <nptl/sysdeps/pthread/timer_settime.c>
37 # undef timer_settime
38 # endif
39
40 # ifdef timer_settime_alias
41 # define timer_settime timer_settime_alias
42 # endif
43
44
45 int
timer_settime(timer_t timerid,int flags,const struct itimerspec * value,struct itimerspec * ovalue)46 timer_settime (
47 timer_t timerid,
48 int flags,
49 const struct itimerspec *value,
50 struct itimerspec *ovalue)
51 {
52 # undef timer_settime
53 # ifndef __ASSUME_POSIX_TIMERS
54 if (__no_posix_timers >= 0)
55 # endif
56 {
57 struct timer *kt = (struct timer *) timerid;
58
59 /* Delete the kernel timer object. */
60 # if defined(__UCLIBC_USE_TIME64__) && defined(__NR_timer_settime64)
61 int res = INLINE_SYSCALL (timer_settime64, 4, kt->ktimerid, flags,
62 TO_ITS64_P(value), ovalue);
63 # else
64 int res = INLINE_SYSCALL (timer_settime, 4, kt->ktimerid, flags,
65 value, ovalue);
66 # endif
67
68 # ifndef __ASSUME_POSIX_TIMERS
69 if (res != -1 || errno != ENOSYS)
70 {
71 /* We know the syscall support is available. */
72 __no_posix_timers = 1;
73 # endif
74 return res;
75 # ifndef __ASSUME_POSIX_TIMERS
76 }
77 # endif
78
79 # ifndef __ASSUME_POSIX_TIMERS
80 __no_posix_timers = -1;
81 # endif
82 }
83
84 # ifndef __ASSUME_POSIX_TIMERS
85 return compat_timer_settime (timerid, flags, value, ovalue);
86 # endif
87 }
88 #else
89 # ifdef timer_settime_alias
90 # define timer_settime timer_settime_alias
91 # endif
92 /* The new system calls are not available. Use the userlevel
93 implementation. */
94 # include <nptl/sysdeps/pthread/timer_settime.c>
95 #endif
96