1
Fork 0

Don't ignore errors of syscalls in std::sys::unix::fd

If any of these syscalls fail, it indicates a programmer error that
should not be silently ignored.
This commit is contained in:
Tobias Bucher 2016-06-23 13:57:55 +02:00
parent 4960f2f907
commit a32244b3d9

View file

@ -65,7 +65,7 @@ impl FileDesc {
pub fn set_cloexec(&self) {
unsafe {
let ret = libc::ioctl(self.fd, libc::FIOCLEX);
debug_assert_eq!(ret, 0);
assert_eq!(ret, 0);
}
}
#[cfg(any(target_env = "newlib", target_os = "solaris", target_os = "emscripten"))]
@ -73,21 +73,21 @@ impl FileDesc {
unsafe {
let previous = libc::fcntl(self.fd, libc::F_GETFD);
let ret = libc::fcntl(self.fd, libc::F_SETFD, previous | libc::FD_CLOEXEC);
debug_assert_eq!(ret, 0);
assert_eq!(ret, 0);
}
}
pub fn set_nonblocking(&self, nonblocking: bool) {
unsafe {
let previous = libc::fcntl(self.fd, libc::F_GETFL);
debug_assert!(previous != -1);
assert!(previous != -1);
let new = if nonblocking {
previous | libc::O_NONBLOCK
} else {
previous & !libc::O_NONBLOCK
};
let ret = libc::fcntl(self.fd, libc::F_SETFL, new);
debug_assert!(ret != -1);
assert!(ret != -1);
}
}