//////////////////////// \brief SysDup(fd) Duplicate a file descriptor \param fd (int) file descriptor to duplicate \return new file descriptor (int) on success, negative error code on failure ////////////////////////
| 2014 | /// \return new file descriptor (int) on success, negative error code on failure |
| 2015 | ///////////////////////////// |
| 2016 | long SysDup(regs64_t* r){ |
| 2017 | int fd = static_cast<int>(SC_ARG0(r)); |
| 2018 | fs_fd_t* handle; |
| 2019 | |
| 2020 | process_t* currentProcess = Scheduler::GetCurrentProcess(); |
| 2021 | if(static_cast<unsigned>(fd) >= currentProcess->fileDescriptors.get_length() || !(handle = currentProcess->fileDescriptors[fd])){ |
| 2022 | return -EBADF; |
| 2023 | } |
| 2024 | |
| 2025 | fs_fd_t* newHandle = new fs_fd_t; |
| 2026 | *newHandle = *handle; |
| 2027 | newHandle->node->handleCount++; |
| 2028 | |
| 2029 | int newFd = currentProcess->fileDescriptors.get_length(); |
| 2030 | currentProcess->fileDescriptors.add_back(newHandle); |
| 2031 | |
| 2032 | return newFd; |
| 2033 | } |
| 2034 | |
| 2035 | ///////////////////////////// |
| 2036 | /// \brief SysGetFileStatusFlags(fd) Get a file handle's mode/status flags |
nothing calls this directly
no test coverage detected