initial commit
[glibc.git] / sysdeps / unix / sysv / linux / timer_settime.c
1 /* Copyright (C) 2003-2022 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 License as
6 published by the Free Software Foundation; either version 2.1 of the
7 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; see the file COPYING.LIB. If
16 not, see <https://www.gnu.org/licenses/>. */
17
18 #include <errno.h>
19 #include <stdlib.h>
20 #include <time.h>
21 #include <sysdep.h>
22 #include <kernel-features.h>
23 #include "kernel-posix-timers.h"
24 #include <shlib-compat.h>
25
26 #if !TIMER_T_WAS_INT_COMPAT
27 int
28 ___timer_settime64 (timer_t timerid, int flags,
29 const struct __itimerspec64 *value,
30 struct __itimerspec64 *ovalue)
31 {
32 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
33
34 # ifdef __ASSUME_TIME64_SYSCALLS
35 # ifndef __NR_timer_settime64
36 # define __NR_timer_settime64 __NR_timer_settime
37 # endif
38 return INLINE_SYSCALL_CALL (timer_settime64, ktimerid, flags, value,
39 ovalue);
40 # else
41 # ifdef __NR_timer_settime64
42 int ret = INLINE_SYSCALL_CALL (timer_settime64, ktimerid, flags, value,
43 ovalue);
44 if (ret == 0 || errno != ENOSYS)
45 return ret;
46 # endif
47 struct itimerspec its32, oits32;
48
49 if (! in_time_t_range ((value->it_value).tv_sec)
50 || ! in_time_t_range ((value->it_interval).tv_sec))
51 {
52 __set_errno (EOVERFLOW);
53 return -1;
54 }
55
56 its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
57 its32.it_value = valid_timespec64_to_timespec (value->it_value);
58
59 int retval = INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags,
60 &its32, ovalue ? &oits32 : NULL);
61 if (retval == 0 && ovalue)
62 {
63 ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
64 ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
65 }
66
67 return retval;
68 # endif
69 }
70
71 # if __TIMESIZE == 64
72 versioned_symbol (libc, ___timer_settime64, timer_settime, GLIBC_2_34);
73 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
74 compat_symbol (librt, ___timer_settime64, timer_settime, GLIBC_2_2);
75 # endif
76
77 #else /* __TIMESIZE != 64 */
78 libc_hidden_ver (___timer_settime64, __timer_settime64)
79 versioned_symbol (libc, ___timer_settime64, __timer_settime64, GLIBC_2_34);
80
81 int
82 __timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
83 struct itimerspec *ovalue)
84 {
85 struct __itimerspec64 its64, oits64;
86 int retval;
87
88 its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
89 its64.it_value = valid_timespec_to_timespec64 (value->it_value);
90
91 retval = __timer_settime64 (timerid, flags, &its64, ovalue ? &oits64 : NULL);
92 if (retval == 0 && ovalue)
93 {
94 ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
95 ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
96 }
97
98 return retval;
99 }
100 versioned_symbol (libc, __timer_settime, timer_settime, GLIBC_2_34);
101
102 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_34)
103 compat_symbol (librt, __timer_settime, timer_settime, GLIBC_2_2);
104 # endif
105 # endif /* __TIMESIZE != 64 */
106
107 #else /* TIMER_T_WAS_INT_COMPAT */
108
109 extern __typeof (timer_settime) __timer_settime_new;
110 libc_hidden_proto (__timer_settime_new)
111
112 int
113 ___timer_settime_new (timer_t timerid, int flags,
114 const struct itimerspec *value,
115 struct itimerspec *ovalue)
116 {
117 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
118
119 return INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags, value, ovalue);
120 }
121 versioned_symbol (libc, ___timer_settime_new, timer_settime, GLIBC_2_34);
122 libc_hidden_ver (___timer_settime_new, __timer_settime_new)
123
124 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_3_3, GLIBC_2_34)
125 compat_symbol (librt, ___timer_settime_new, timer_settime, GLIBC_2_3_3);
126 # endif
127
128 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
129 int
130 __timer_settime_old (int timerid, int flags, const struct itimerspec *value,
131 struct itimerspec *ovalue)
132 {
133 return __timer_settime_new (__timer_compat_list[timerid], flags,
134 value, ovalue);
135 }
136 compat_symbol (librt, __timer_settime_old, timer_settime, GLIBC_2_2);
137 # endif
138
139 #endif /* TIMER_T_WAS_INT_COMPAT */