projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
passfd: allow compilation on mingw
[gnulib.git]
/
lib
/
passfd.c
diff --git
a/lib/passfd.c
b/lib/passfd.c
index
1ab94b4
..
5d4c6a7
100644
(file)
--- a/
lib/passfd.c
+++ b/
lib/passfd.c
@@
-24,7
+24,6
@@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
-#include <sys/uio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/socket.h>
@@
-38,6
+37,7
@@
# define MSG_CMSG_CLOEXEC 0
#endif
# define MSG_CMSG_CLOEXEC 0
#endif
+#if HAVE_SENDMSG
/* sendfd sends the file descriptor fd along the socket
to a process calling recvfd on the other end.
/* sendfd sends the file descriptor fd along the socket
to a process calling recvfd on the other end.
@@
-49,10
+49,10
@@
sendfd (int sock, int fd)
char send = 0;
struct iovec iov;
struct msghdr msg;
char send = 0;
struct iovec iov;
struct msghdr msg;
-#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+#
if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
struct cmsghdr *cmsg;
char buf[CMSG_SPACE (sizeof fd)];
struct cmsghdr *cmsg;
char buf[CMSG_SPACE (sizeof fd)];
-#endif
+#
endif
/* send at least one char */
memset (&msg, 0, sizeof msg);
/* send at least one char */
memset (&msg, 0, sizeof msg);
@@
-63,7
+63,7
@@
sendfd (int sock, int fd)
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
-#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+#
if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
msg.msg_control = buf;
msg.msg_controllen = sizeof buf;
cmsg = CMSG_FIRSTHDR (&msg);
msg.msg_control = buf;
msg.msg_controllen = sizeof buf;
cmsg = CMSG_FIRSTHDR (&msg);
@@
-72,19
+72,29
@@
sendfd (int sock, int fd)
cmsg->cmsg_len = CMSG_LEN (sizeof fd);
/* Initialize the payload: */
memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
cmsg->cmsg_len = CMSG_LEN (sizeof fd);
/* Initialize the payload: */
memcpy (CMSG_DATA (cmsg), &fd, sizeof fd);
-#elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
+#
elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
msg.msg_accrights = &fd;
msg.msg_accrightslen = sizeof fd;
msg.msg_accrights = &fd;
msg.msg_accrightslen = sizeof fd;
-#else
+#
else
errno = ENOSYS;
return -1;
errno = ENOSYS;
return -1;
-#endif
+#
endif
if (sendmsg (sock, &msg, 0) != iov.iov_len)
return -1;
return 0;
}
if (sendmsg (sock, &msg, 0) != iov.iov_len)
return -1;
return 0;
}
+#else
+int
+sendfd (int sock _GL_UNUSED, int fd _GL_UNUSED)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif
+
+#if HAVE_RECVMSG
/* recvfd receives a file descriptor through the socket.
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>).
/* recvfd receives a file descriptor through the socket.
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>).
@@
-97,11
+107,11
@@
recvfd (int sock, int flags)
struct iovec iov;
struct msghdr msg;
int fd = -1;
struct iovec iov;
struct msghdr msg;
int fd = -1;
-#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+#
if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
struct cmsghdr *cmsg;
char buf[CMSG_SPACE (sizeof fd)];
int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0;
struct cmsghdr *cmsg;
char buf[CMSG_SPACE (sizeof fd)];
int flags_recvmsg = flags & O_CLOEXEC ? MSG_CMSG_CLOEXEC : 0;
-#endif
+#
endif
if ((flags & ~O_CLOEXEC) != 0)
{
if ((flags & ~O_CLOEXEC) != 0)
{
@@
-118,7
+128,7
@@
recvfd (int sock, int flags)
msg.msg_name = NULL;
msg.msg_namelen = 0;
msg.msg_name = NULL;
msg.msg_namelen = 0;
-#if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
+#
if HAVE_UNIXSOCKET_SCM_RIGHTS_BSD44_WAY
msg.msg_control = buf;
msg.msg_controllen = sizeof buf;
cmsg = CMSG_FIRSTHDR (&msg);
msg.msg_control = buf;
msg.msg_controllen = sizeof buf;
cmsg = CMSG_FIRSTHDR (&msg);
@@
-156,7
+166,7
@@
recvfd (int sock, int flags)
}
}
}
}
-#elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
+#
elif HAVE_UNIXSOCKET_SCM_RIGHTS_BSD43_WAY
msg.msg_accrights = &fd;
msg.msg_accrightslen = sizeof fd;
if (recvmsg (sock, &msg, 0) < 0)
msg.msg_accrights = &fd;
msg.msg_accrightslen = sizeof fd;
if (recvmsg (sock, &msg, 0) < 0)
@@
-173,9
+183,17
@@
recvfd (int sock, int flags)
return -1;
}
}
return -1;
}
}
-#else
+#
else
errno = ENOSYS;
errno = ENOSYS;
-#endif
+#
endif
return fd;
}
return fd;
}
+#else
+int
+recvfd (int sock _GL_UNUSED, int flags _GL_UNUSED)
+{
+ errno = ENOSYS;
+ return -1;
+}
+#endif