1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-25 09:26:17 +04:00

Merge pull request #49 from rcore-os/support-fcntl-dupfd

This commit is contained in:
Chen 2020-04-27 13:02:55 +08:00 committed by GitHub
commit 0bd8e58a47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1097,8 +1097,22 @@ impl Syscall<'_> {
pub fn sys_fcntl(&mut self, fd: usize, cmd: usize, arg: usize) -> SysResult {
info!("fcntl: fd: {}, cmd: {:x}, arg: {}", fd, cmd, arg);
let mut proc = self.process();
let file_like = proc.get_file_like(fd)?;
file_like.fcntl(cmd, arg)
const F_DUPFD_CLOEXEC: usize = 1030;
if cmd == F_DUPFD_CLOEXEC {
// dupfd with close on exec
// TODO: close on exec
let file_like = proc.get_file_like(fd)?.clone();
for new_fd in arg.. {
if proc.files.get(&new_fd).is_none() {
proc.files.insert(new_fd, file_like);
return Ok(new_fd);
}
}
panic!("no available fd found")
} else {
let file_like = proc.get_file_like(fd)?;
file_like.fcntl(cmd, arg)
}
}
}