Commit 68c02fc9 authored by Max Kellermann's avatar Max Kellermann

fd_util: add function dup_cloexec()

Unfortunately, there's no "optimized" implementation here. We can't use Linux's proprietary system call dup3(), because it would require us to specify the new descriptor.
parent d18c1b1a
......@@ -104,6 +104,16 @@ fd_set_nonblock(int fd)
}
int
dup_cloexec(int oldfd)
{
int newfd = dup(oldfd);
if (newfd >= 0)
fd_set_nonblock(newfd);
return newfd;
}
int
open_cloexec(const char *path_fs, int flags, int mode)
{
int fd;
......
......@@ -50,6 +50,13 @@
struct sockaddr;
/**
* Wrapper for dup(), which sets the CLOEXEC flag on the new
* descriptor.
*/
int
dup_cloexec(int oldfd);
/**
* Wrapper for open(), which sets the CLOEXEC flag (atomically if
* supported by the OS).
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment