1 #include <sys/socket.h>
6 #define IS32BIT(x) !((x)+0x80000000ULL>>32)
7 #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
9 int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
11 const struct timeval *tv;
15 int r = __socketcall(setsockopt, fd, level, optname, optval, optlen, 0);
17 if (r==-ENOPROTOOPT) switch (level) {
22 if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break;
23 if (optlen < sizeof *tv) return __syscall_ret(-EINVAL);
27 if (!IS32BIT(s)) return __syscall_ret(-ENOTSUP);
29 if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD;
30 if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD;
32 r = __socketcall(setsockopt, fd, level, optname,
33 ((long[]){s, CLAMP(us)}), 2*sizeof(long), 0);
37 if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break;
38 if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD;
39 if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD;
40 r = __socketcall(setsockopt, fd, level,
41 optname, optval, optlen, 0);
45 return __syscall_ret(r);