aboutsummaryrefslogtreecommitdiffstats
path: root/src/fd_util.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/fd_util.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/fd_util.c b/src/fd_util.c
index e385be0ce..d8fe166d7 100644
--- a/src/fd_util.c
+++ b/src/fd_util.c
@@ -174,6 +174,30 @@ pipe_cloexec_nonblock(int fd[2])
#endif
}
+#ifndef WIN32
+
+int
+socketpair_cloexec(int domain, int type, int protocol, int sv[2])
+{
+ int ret;
+
+#ifdef SOCK_CLOEXEC
+ ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
+ if (ret >= 0 || errno != EINVAL)
+ return ret;
+#endif
+
+ ret = socketpair(domain, type, protocol, sv);
+ if (ret >= 0) {
+ fd_set_cloexec(sv[0], true);
+ fd_set_cloexec(sv[1], true);
+ }
+
+ return ret;
+}
+
+#endif
+
int
socket_cloexec_nonblock(int domain, int type, int protocol)
{