-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "cloexec.h"
+/* The code that uses CMSG_FIRSTHDR is enabled on
+ Linux, Mac OS X, FreeBSD, OpenBSD, NetBSD, AIX, OSF/1, Cygwin.
+ The code that uses HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS is enabled on
+ HP-UX, IRIX, Solaris. */
+
+/* MSG_CMSG_CLOEXEC is defined only on Linux, as of 2011. */
#ifndef MSG_CMSG_CLOEXEC
# define MSG_CMSG_CLOEXEC 0
#endif
int
sendfd (int sock, int fd)
{
- char send = 0;
+ char byte = 0;
struct iovec iov;
struct msghdr msg;
# ifdef CMSG_FIRSTHDR
/* send at least one char */
memset (&msg, 0, sizeof msg);
- iov.iov_base = &send;
+ iov.iov_base = &byte;
iov.iov_len = 1;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
/* recvfd receives a file descriptor through the socket.
The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>).
- Return 0 on success, or -1 with errno set in case of error.
+ Return the fd on success, or -1 with errno set in case of error.
*/
int
recvfd (int sock, int flags)
{
- char recv = 0;
+ char byte = 0;
struct iovec iov;
struct msghdr msg;
int fd = -1;
/* send at least one char */
memset (&msg, 0, sizeof msg);
- iov.iov_base = &recv;
+ iov.iov_base = &byte;
iov.iov_len = 1;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;