]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/timerfd_settime.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / timerfd_settime.c
1 /* timerfd_settime -- start or stop the timer referred to by file descriptor.
2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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 <https://www.gnu.org/licenses/>. */
18
19 #include <errno.h>
20 #include <stdlib.h>
21 #include <time.h>
22 #include <sysdep.h>
23 #include <kernel-features.h>
24
25 int
26 __timerfd_settime64 (int fd, int flags, const struct __itimerspec64 *value,
27 struct __itimerspec64 *ovalue)
28 {
29 #ifndef __NR_timerfd_settime64
30 # define __NR_timerfd_settime64 __NR_timerfd_settime
31 #endif
32 int ret = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue);
33 #ifndef __ASSUME_TIME64_SYSCALLS
34 if (ret == 0 || errno != ENOSYS)
35 return ret;
36
37 if (! in_time_t_range ((value->it_value).tv_sec)
38 || ! in_time_t_range ((value->it_interval).tv_sec))
39 {
40 __set_errno (EOVERFLOW);
41 return -1;
42 }
43
44 struct itimerspec its32, oits32;
45 its32.it_interval = valid_timespec64_to_timespec (value->it_interval);
46 its32.it_value = valid_timespec64_to_timespec (value->it_value);
47
48 ret = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags,
49 &its32, ovalue ? &oits32 : NULL);
50 if (ret == 0 && ovalue != NULL)
51 {
52 ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval);
53 ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value);
54 }
55 #endif
56 return ret;
57 }
58
59 #if __TIMESIZE != 64
60 libc_hidden_def (__timerfd_settime64)
61
62 int
63 __timerfd_settime (int fd, int flags, const struct itimerspec *value,
64 struct itimerspec *ovalue)
65 {
66 struct __itimerspec64 its64, oits64;
67 int retval;
68
69 its64.it_interval = valid_timespec_to_timespec64 (value->it_interval);
70 its64.it_value = valid_timespec_to_timespec64 (value->it_value);
71
72 retval = __timerfd_settime64 (fd, flags, &its64, ovalue ? &oits64 : NULL);
73 if (retval == 0 && ovalue)
74 {
75 ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval);
76 ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value);
77 }
78
79 return retval;
80 }
81 #endif
82 strong_alias (__timerfd_settime, timerfd_settime)