dup2 (nr 33)
Linux Signature
int dup2(int oldfd, int newfd);
Description
Duplicates file descriptor oldfd to newfd. If newfd is already open, it is silently closed first.
Current Implementation
- If
oldfd == newfd: validates thatoldfdis open, returnsnewfd. - Reads the
FdEntry(handle + flags) fromoldfd. - Clones the
Arc<dyn FileHandle>and installs it atnewfd. - The new fd does not inherit
FD_CLOEXECfrom the old fd (per POSIX). - If
newfdwas previously open, its old handle is dropped (refcount decremented). - The fd table is extended if
newfdexceeds the current length.
Source: osl/src/syscalls/fs.rs — sys_dup2
Errors
| Errno | Condition |
|---|---|
-EBADF (-9) | oldfd is not a valid open fd |