Skip to content

Commit

Permalink
[orbis-kernel] implement sys_dup2/sys_dup
Browse files Browse the repository at this point in the history
  • Loading branch information
DHrpcs3 committed Oct 31, 2023
1 parent e989744 commit 39092c7
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions orbis-kernel/src/sys/sys_descrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,27 @@ orbis::SysResult orbis::sys_getdtablesize(Thread *thread) {
return ErrorCode::NOSYS;
}
orbis::SysResult orbis::sys_dup2(Thread *thread, uint from, uint to) {
return ErrorCode::NOSYS;
if (to == 1 || to == 2) { // HACK: ignore setup /dev/console to stdout/stderr
return {};
}

std::lock_guard lock(thread->tproc->fileDescriptors.mutex);

auto file = thread->tproc->fileDescriptors.get(from);
if (file == nullptr) {
return ErrorCode::BADF;
}
thread->tproc->fileDescriptors.close(to);
thread->tproc->fileDescriptors.insert(to, file);
return {};
}
orbis::SysResult orbis::sys_dup(Thread *thread, uint fd) {
return ErrorCode::NOSYS;
auto file = thread->tproc->fileDescriptors.get(fd);
if (file == nullptr) {
return ErrorCode::BADF;
}
thread->retval[0] = thread->tproc->fileDescriptors.insert(std::move(file));
return {};
}
orbis::SysResult orbis::sys_fcntl(Thread *thread, sint fd, sint cmd,
slong arg) {
Expand Down

0 comments on commit 39092c7

Please sign in to comment.