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:
@@ -103,6 +103,16 @@ fd_set_nonblock(int fd)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
dup_cloexec(int oldfd)
|
||||||
|
{
|
||||||
|
int newfd = dup(oldfd);
|
||||||
|
if (newfd >= 0)
|
||||||
|
fd_set_nonblock(newfd);
|
||||||
|
|
||||||
|
return newfd;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
open_cloexec(const char *path_fs, int flags, int mode)
|
open_cloexec(const char *path_fs, int flags, int mode)
|
||||||
{
|
{
|
||||||
|
@@ -49,6 +49,13 @@
|
|||||||
|
|
||||||
struct sockaddr;
|
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
|
* Wrapper for open(), which sets the CLOEXEC flag (atomically if
|
||||||
* supported by the OS).
|
* supported by the OS).
|
||||||
|
Reference in New Issue
Block a user