From 330f54ac7f780872223f9cac62347393ffb4ef86 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 6 Jul 2017 21:42:01 +0000 Subject: Initial commit --- src/libwpactrl/wpactrl_fd_recv.c | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/libwpactrl/wpactrl_fd_recv.c (limited to 'src/libwpactrl/wpactrl_fd_recv.c') diff --git a/src/libwpactrl/wpactrl_fd_recv.c b/src/libwpactrl/wpactrl_fd_recv.c new file mode 100644 index 0000000..3e2a006 --- /dev/null +++ b/src/libwpactrl/wpactrl_fd_recv.c @@ -0,0 +1,47 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include "wpactrl-internal.h" + +ssize_t wpactrl_fd_recv (int fd, char *s, size_t len) +{ + static int const bsd_braindeadness_workaround_flags = +#ifdef SKALIBS_HASMSGDONTWAIT + MSG_DONTWAIT +#else + 0 +#endif + | +#ifdef SKALIBS_HASNBWAITALL + MSG_WAITALL +#else + 0 +#endif + | +#ifdef SKALIBS_HASCMSGCLOEXEC + MSG_CMSG_CLOEXEC +#else + 0 +#endif + ; + struct iovec iov = { .iov_base = s, .iov_len = len } ; + struct msghdr msghdr = + { + .msg_name = 0, + .msg_namelen = 0, + .msg_iov = &iov, + .msg_iovlen = 1, + .msg_flags = 0, + .msg_control = 0, + .msg_controllen = 0 + } ; + ssize_t r ; + do r = recvmsg(fd, &msghdr, bsd_braindeadness_workaround_flags) ; + while (r == -1 && errno == EINTR) ; + return r > 0 && msghdr.msg_flags | MSG_TRUNC ? (errno = EMSGSIZE, -1) : r ; +} -- cgit v1.2.3