diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-12-04 11:39:55 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-12-04 11:39:55 -0500 |
commit | 49e767ccb9dcfd2161b89f0d7a980eb85f056c5d (patch) | |
tree | 3cdb06282e30c02e3b37615d39b5c1c75af53e3d /util.c | |
parent | 6962fb41b8e57f8bc817b477cf16262a0ce876d5 (diff) | |
download | bfs-49e767ccb9dcfd2161b89f0d7a980eb85f056c5d.tar.xz |
Move portability code into util.h
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -58,3 +58,21 @@ int redirect(int fd, const char *path, int flags, ...) { return ret; } + +int dup_cloexec(int fd) { +#ifdef F_DUPFD_CLOEXEC + return fcntl(fd, F_DUPFD_CLOEXEC, 0); +#else + int ret = dup(fd); + if (ret < 0) { + return -1; + } + + if (fcntl(ret, F_SETFD, FD_CLOEXEC) == -1) { + close(ret); + return -1; + } + + return ret; +#endif +} |