Skip to content

Commit a0b5dfe

Browse files
committed
Add fcntl
1 parent 0bb9a95 commit a0b5dfe

File tree

1 file changed

+11
-5
lines changed
  • src/libstd/sys/redox

1 file changed

+11
-5
lines changed

src/libstd/sys/redox/fd.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,19 @@ impl FileDesc {
4949
}
5050

5151
pub fn set_cloexec(&self) -> io::Result<()> {
52-
::sys_common::util::dumb_print(format_args!("{}: set cloexec\n", self.fd));
53-
unimplemented!();
52+
let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
53+
flags |= libc::O_CLOEXEC;
54+
cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(()))
5455
}
5556

56-
pub fn set_nonblocking(&self, _nonblocking: bool) -> io::Result<()> {
57-
::sys_common::util::dumb_print(format_args!("{}: set nonblocking\n", self.fd));
58-
unimplemented!();
57+
pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
58+
let mut flags = cvt(libc::fcntl(self.fd, libc::F_GETFL, 0))?;
59+
if nonblocking {
60+
flags |= libc::O_NONBLOCK;
61+
} else {
62+
flags &= !libc::O_NONBLOCK;
63+
}
64+
cvt(libc::fcntl(self.fd, libc::F_SETFL, flags)).and(Ok(()))
5965
}
6066

6167
pub fn duplicate(&self) -> io::Result<FileDesc> {

0 commit comments

Comments
 (0)