Add crt1-2.0.o for glibc 2.0 compatibility tests
[glibc.git] / sysdeps / unix / sysv / linux / timer_settime.c
blob8986462d8e8eef24a608c53c476cda2a0a9dc066
1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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/>. */
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>
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)
32 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
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;
49 if (! in_int32_t_range ((value->it_value).tv_sec)
50 || ! in_int32_t_range ((value->it_interval).tv_sec))
52 __set_errno (EOVERFLOW);
53 return -1;
56 its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
57 its32.it_value = valid_timespec64_to_timespec (value->it_value);
59 int retval = INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags,
60 &its32, ovalue ? &oits32 : NULL);
61 if (retval == 0 && ovalue)
63 ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
64 ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
67 return retval;
68 # endif
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
77 #else /* __TIMESIZE != 64 */
78 libc_hidden_ver (___timer_settime64, __timer_settime64)
79 versioned_symbol (libc, ___timer_settime64, __timer_settime64, GLIBC_2_34);
81 int
82 __timer_settime (timer_t timerid, int flags, const struct itimerspec *value,
83 struct itimerspec *ovalue)
85 struct __itimerspec64 its64, oits64;
86 int retval;
88 its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
89 its64.it_value = valid_timespec_to_timespec64 (value->it_value);
91 retval = __timer_settime64 (timerid, flags, &its64, ovalue ? &oits64 : NULL);
92 if (retval == 0 && ovalue)
94 ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
95 ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
98 return retval;
100 versioned_symbol (libc, __timer_settime, timer_settime, GLIBC_2_34);
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 */
107 #else /* TIMER_T_WAS_INT_COMPAT */
109 extern __typeof (timer_settime) __timer_settime_new;
110 libc_hidden_proto (__timer_settime_new)
113 ___timer_settime_new (timer_t timerid, int flags,
114 const struct itimerspec *value,
115 struct itimerspec *ovalue)
117 kernel_timer_t ktimerid = timerid_to_kernel_timer (timerid);
119 return INLINE_SYSCALL_CALL (timer_settime, ktimerid, flags, value, ovalue);
121 versioned_symbol (libc, ___timer_settime_new, timer_settime, GLIBC_2_34);
122 libc_hidden_ver (___timer_settime_new, __timer_settime_new)
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
128 # if OTHER_SHLIB_COMPAT (librt, GLIBC_2_2, GLIBC_2_3_3)
130 __timer_settime_old (int timerid, int flags, const struct itimerspec *value,
131 struct itimerspec *ovalue)
133 return __timer_settime_new (__timer_compat_list[timerid], flags,
134 value, ovalue);
136 compat_symbol (librt, __timer_settime_old, timer_settime, GLIBC_2_2);
137 # endif
139 #endif /* TIMER_T_WAS_INT_COMPAT */