【修复】 修复dup系统调用对用户态的返回值问题

This commit is contained in:
zhuzhuzhu 2024-08-25 22:56:47 +08:00 committed by GitHub
parent c4c227e367
commit d9fac09f71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -537,6 +537,7 @@ int dfs_dup(int oldfd, int startfd)
fdt = dfs_fdtable_get();
if ((oldfd < 0) || (oldfd >= fdt->maxfd))
{
rt_set_errno(-EBADF);
goto exit;
}
if (!fdt->fds[oldfd])
@ -668,12 +669,17 @@ sysret_t sys_dup(int oldfd)
int sys_dup(int oldfd)
#endif
{
int err = 0;
int newfd = dfs_dup(oldfd, (dfs_fdtable_get() == &_fdtab) ? DFS_STDIO_OFFSET : 0);
if(newfd < 0)
{
err = rt_get_errno();
}
#ifdef RT_USING_SMART
return (sysret_t)newfd;
return err < 0 ? err : newfd;
#else
return newfd;
return err < 0 ? err : newfd;
#endif
}