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:
parent
d18c1b1a0a
commit
68c02fc95a
@ -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)
|
||||
{
|
||||
|
@ -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).
|
||||
|
Loading…
Reference in New Issue
Block a user