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.
This commit is contained in:
Max Kellermann 2010-08-03 18:03:55 +02:00
parent d18c1b1a0a
commit 68c02fc95a
2 changed files with 17 additions and 0 deletions

View File

@ -103,6 +103,16 @@ fd_set_nonblock(int fd)
#endif
}
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)
{

View File

@ -49,6 +49,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).