Fix usage of O_CLOEXEC in SETFL (#596)
* Fix usage of O_CLOEXEC in SETFL
* Use GETFD instead of GETFL for cloexec
diff --git a/src/sys/unix/io.rs b/src/sys/unix/io.rs
index ad51c9d..3f4cb33 100644
--- a/src/sys/unix/io.rs
+++ b/src/sys/unix/io.rs
@@ -18,8 +18,8 @@
pub fn set_cloexec(fd: libc::c_int) -> io::Result<()> {
unsafe {
- let flags = libc::fcntl(fd, libc::F_GETFL);
- cvt(libc::fcntl(fd, libc::F_SETFL, flags | libc::O_CLOEXEC)).map(|_| ())
+ let flags = libc::fcntl(fd, libc::F_GETFD);
+ cvt(libc::fcntl(fd, libc::F_SETFD, flags | libc::FD_CLOEXEC)).map(|_| ())
}
}