From 68c02fc95af57a0b3be64aa214125be2d3ed1cf7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 3 Aug 2010 18:03:55 +0200 Subject: 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. --- src/fd_util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/fd_util.c') diff --git a/src/fd_util.c b/src/fd_util.c index b9443b03d..769823bc4 100644 --- a/src/fd_util.c +++ b/src/fd_util.c @@ -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) { -- cgit v1.2.3