1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

More work towards getting bash to build.

Implemented some syscalls: dup(), dup2(), getdtablesize().
FileHandle is now a retainable, since that's needed for dup()'ed fd's.
I didn't really test any of this beyond a basic smoke check.
This commit is contained in:
Andreas Kling 2018-11-05 19:01:22 +01:00
parent 82f84bab11
commit 9f2b9c82bf
17 changed files with 114 additions and 23 deletions

View file

@ -1158,7 +1158,6 @@ int Process::sys$open(const char* path, int options)
if (!m_file_descriptors[fd])
break;
}
handle->setFD(fd);
m_file_descriptors[fd] = move(handle);
return fd;
}
@ -1435,3 +1434,35 @@ int Process::sys$tcsetpgrp(int fd, pid_t pgid)
tty.set_pgid(pgid);
return 0;
}
int Process::sys$getdtablesize()
{
return m_max_open_file_descriptors;
}
int Process::sys$dup(int old_fd)
{
auto* handle = fileHandleIfExists(old_fd);
if (!handle)
return -EBADF;
if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
return -EMFILE;
int new_fd = 0;
for (; new_fd < m_max_open_file_descriptors; ++new_fd) {
if (!m_file_descriptors[new_fd])
break;
}
m_file_descriptors[new_fd] = handle;
return new_fd;
}
int Process::sys$dup2(int old_fd, int new_fd)
{
auto* handle = fileHandleIfExists(old_fd);
if (!handle)
return -EBADF;
if (number_of_open_file_descriptors() == m_max_open_file_descriptors)
return -EMFILE;
m_file_descriptors[new_fd] = handle;
return new_fd;
}