Noux: add dup() to libc_noux

This library function is implemented upon SYSCALL_DUP2. Therfor the
syscall was slightly changed. It now returns the new allocated fd in
dup2_out.fd.
This commit is contained in:
Josef Söntgen 2012-10-04 12:48:41 +02:00 committed by Norman Feske
parent 7a619b9ede
commit ac3a362fdf
3 changed files with 20 additions and 3 deletions

View File

@ -423,7 +423,7 @@ namespace Noux {
{ int pid; int status; });
SYSIO_DECL(pipe, { }, { int fd[2]; });
SYSIO_DECL(dup2, { int fd; int to_fd; }, { });
SYSIO_DECL(dup2, { int fd; int to_fd; }, { int fd; });
SYSIO_DECL(unlink, { Path path; }, { });

View File

@ -176,6 +176,20 @@ extern "C" uid_t geteuid()
}
extern "C" int dup(int ofd)
{
sysio()->dup2_in.fd = ofd;
sysio()->dup2_in.to_fd = -1;
if (!noux()->syscall(Noux::Session::SYSCALL_DUP2)) {
errno = EINVAL;
return -1;
}
return sysio()->dup2_out.fd;
}
/**
* Utility to copy-out syscall results to buf struct
*

View File

@ -549,8 +549,11 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc)
case SYSCALL_DUP2:
{
add_io_channel(io_channel_by_fd(_sysio->dup2_in.fd),
_sysio->dup2_in.to_fd);
int fd = add_io_channel(io_channel_by_fd(_sysio->dup2_in.fd),
_sysio->dup2_in.to_fd);
_sysio->dup2_out.fd = fd;
return true;
}