mirror of
https://github.com/apache/nuttx.git
synced 2026-10-06 22:05:21 +00:00
fs/dup: remove template filep to optimize dup operation
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
e8f9ef022f
commit
5b889b9270
1 changed files with 15 additions and 14 deletions
|
|
@ -52,27 +52,28 @@
|
|||
|
||||
int file_dup(FAR struct file *filep, int minfd, int flags)
|
||||
{
|
||||
struct file filep2;
|
||||
FAR struct file *filep2;
|
||||
int fd2;
|
||||
int ret;
|
||||
|
||||
/* Let file_dup3() do the real work */
|
||||
|
||||
memset(&filep2, 0, sizeof(filep2));
|
||||
ret = file_dup3(filep, &filep2, flags);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
fd2 = file_allocate(filep2.f_inode, filep2.f_oflags,
|
||||
filep2.f_pos, filep2.f_priv, minfd, false);
|
||||
fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true);
|
||||
if (fd2 < 0)
|
||||
{
|
||||
file_close(&filep2);
|
||||
return fd2;
|
||||
}
|
||||
|
||||
return fd2;
|
||||
ret = fs_getfilep(fd2, &filep2);
|
||||
DEBUGASSERT(ret >= 0);
|
||||
|
||||
ret = file_dup3(filep, filep2, flags);
|
||||
fs_putfilep(filep2);
|
||||
if (ret >= 0)
|
||||
{
|
||||
return fd2;
|
||||
}
|
||||
|
||||
fs_putfilep(filep2);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue