| 1 | /* timerfd_settime -- start or stop the timer referred to by file descriptor. |
| 2 | Copyright (C) 2020 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 | #ifdef __ASSUME_TIME64_SYSCALLS |
| 30 | # ifndef __NR_timerfd_settime64 |
| 31 | # define __NR_timerfd_settime64 __NR_timerfd_settime |
| 32 | # endif |
| 33 | return INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); |
| 34 | #else |
| 35 | # ifdef __NR_timerfd_settime64 |
| 36 | int ret = INLINE_SYSCALL_CALL (timerfd_settime64, fd, flags, value, ovalue); |
| 37 | if (ret == 0 || errno != ENOSYS) |
| 38 | return ret; |
| 39 | # endif |
| 40 | struct itimerspec its32, oits32; |
| 41 | |
| 42 | if (! in_time_t_range ((value->it_value).tv_sec) |
| 43 | || ! in_time_t_range ((value->it_interval).tv_sec)) |
| 44 | { |
| 45 | __set_errno (EOVERFLOW); |
| 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | its32.it_interval = valid_timespec64_to_timespec (value->it_interval); |
| 50 | its32.it_value = valid_timespec64_to_timespec (value->it_value); |
| 51 | |
| 52 | int retval = INLINE_SYSCALL_CALL (timerfd_settime, fd, flags, |
| 53 | &its32, ovalue ? &oits32 : NULL); |
| 54 | if (retval == 0 && ovalue) |
| 55 | { |
| 56 | ovalue->it_interval = valid_timespec_to_timespec64 (oits32.it_interval); |
| 57 | ovalue->it_value = valid_timespec_to_timespec64 (oits32.it_value); |
| 58 | } |
| 59 | |
| 60 | return retval; |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | #if __TIMESIZE != 64 |
| 65 | libc_hidden_def (__timerfd_settime64) |
| 66 | |
| 67 | int |
| 68 | __timerfd_settime (int fd, int flags, const struct itimerspec *value, |
| 69 | struct itimerspec *ovalue) |
| 70 | { |
| 71 | struct __itimerspec64 its64, oits64; |
| 72 | int retval; |
| 73 | |
| 74 | its64.it_interval = valid_timespec_to_timespec64 (value->it_interval); |
| 75 | its64.it_value = valid_timespec_to_timespec64 (value->it_value); |
| 76 | |
| 77 | retval = __timerfd_settime64 (fd, flags, &its64, ovalue ? &oits64 : NULL); |
| 78 | if (retval == 0 && ovalue) |
| 79 | { |
| 80 | ovalue->it_interval = valid_timespec64_to_timespec (oits64.it_interval); |
| 81 | ovalue->it_value = valid_timespec64_to_timespec (oits64.it_value); |
| 82 | } |
| 83 | |
| 84 | return retval; |
| 85 | } |
| 86 | #endif |
| 87 | strong_alias (__timerfd_settime, timerfd_settime) |
| 88 | |