1 | /* Copyright (C) 2010-2021 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. |
3 | Contributed by Andreas Schwab <schwab@redhat.com>, 2010. |
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 |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the 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; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <sys/socket.h> |
20 | #include <sysdep.h> |
21 | #include <socketcall.h> |
22 | |
23 | int |
24 | __recvmmsg64 (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, |
25 | struct __timespec64 *timeout) |
26 | { |
27 | #ifndef __NR_recvmmsg_time64 |
28 | # define __NR_recvmmsg_time64 __NR_recvmmsg |
29 | #endif |
30 | int r = SYSCALL_CANCEL (recvmmsg_time64, fd, vmessages, vlen, flags, |
31 | timeout); |
32 | #ifndef __ASSUME_TIME64_SYSCALLS |
33 | if (r >= 0 || errno != ENOSYS) |
34 | return r; |
35 | |
36 | struct timespec ts32, *pts32 = NULL; |
37 | if (timeout != NULL) |
38 | { |
39 | if (! in_time_t_range (timeout->tv_sec)) |
40 | { |
41 | __set_errno (EINVAL); |
42 | return -1; |
43 | } |
44 | ts32 = valid_timespec64_to_timespec (*timeout); |
45 | pts32 = &ts32; |
46 | } |
47 | # ifdef __ASSUME_RECVMMSG_SYSCALL |
48 | r = SYSCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); |
49 | # else |
50 | r = SOCKETCALL_CANCEL (recvmmsg, fd, vmessages, vlen, flags, pts32); |
51 | # endif |
52 | if (r >= 0 && timeout != NULL) |
53 | *timeout = valid_timespec_to_timespec64 (ts32); |
54 | #endif /* __ASSUME_TIME64_SYSCALLS */ |
55 | return r; |
56 | } |
57 | #if __TIMESIZE != 64 |
58 | libc_hidden_def (__recvmmsg64) |
59 | |
60 | int |
61 | __recvmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags, |
62 | struct timespec *timeout) |
63 | { |
64 | struct __timespec64 ts64, *pts64 = NULL; |
65 | if (timeout != NULL) |
66 | { |
67 | ts64 = valid_timespec_to_timespec64 (*timeout); |
68 | pts64 = &ts64; |
69 | } |
70 | int r = __recvmmsg64 (fd, vmessages, vlen, flags, pts64); |
71 | if (r >= 0 && timeout != NULL) |
72 | /* The remanining timeout will be always less the input TIMEOUT. */ |
73 | *timeout = valid_timespec64_to_timespec (ts64); |
74 | return r; |
75 | } |
76 | #endif |
77 | weak_alias (__recvmmsg, recvmmsg) |
78 | |