diff options
author | Max Kellermann <max@duempel.org> | 2010-08-03 17:47:34 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-08-03 17:51:35 +0200 |
commit | c980fc653d0bfe1b4744e7e8364b37225ac38746 (patch) | |
tree | 3adce1ca55e8eb2c0ef9625e224dfcdfacd6b7b1 | |
parent | 36782a977a4c5002cf5491c3199a040d50fe296c (diff) | |
download | mpd-c980fc653d0bfe1b4744e7e8364b37225ac38746.tar.gz mpd-c980fc653d0bfe1b4744e7e8364b37225ac38746.tar.xz mpd-c980fc653d0bfe1b4744e7e8364b37225ac38746.zip |
fd_util: add function socketpair_cloexec()
Diffstat (limited to '')
-rw-r--r-- | src/fd_util.c | 24 | ||||
-rw-r--r-- | src/fd_util.h | 11 |
2 files changed, 35 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) { diff --git a/src/fd_util.h b/src/fd_util.h index b704d3d2e..b49a51373 100644 --- a/src/fd_util.h +++ b/src/fd_util.h @@ -65,6 +65,17 @@ pipe_cloexec(int fd[2]); int pipe_cloexec_nonblock(int fd[2]); +#ifndef WIN32 + +/** + * Wrapper for socketpair(), which sets the CLOEXEC flag (atomically + * if supported by the OS). + */ +int +socketpair_cloexec(int domain, int type, int protocol, int sv[2]); + +#endif + /** * Wrapper for socket(), which sets the CLOEXEC and the NONBLOCK flag * (atomically if supported by the OS). |