MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / SysDup

Function SysDup

Kernel/src/arch/x86_64/syscalls.cpp:2016–2033  ·  view source on GitHub ↗

//////////////////////// \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 ////////////////////////

Source from the content-addressed store, hash-verified

2014/// \return new file descriptor (int) on success, negative error code on failure
2015/////////////////////////////
2016long 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

Callers

nothing calls this directly

Calls 3

GetCurrentProcessFunction · 0.85
get_lengthMethod · 0.45
add_backMethod · 0.45

Tested by

no test coverage detected