Skip to content

Commit

Permalink
fs/dup: remove template filep to optimize dup operation
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
  • Loading branch information
Donny9 authored and xiaoxiang781216 committed Sep 30, 2024
1 parent e8f9ef0 commit 5b889b9
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions fs/vfs/fs_dup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true);
if (fd2 < 0)
{
return ret;
return fd2;
}

fd2 = file_allocate(filep2.f_inode, filep2.f_oflags,
filep2.f_pos, filep2.f_priv, minfd, false);
if (fd2 < 0)
ret = fs_getfilep(fd2, &filep2);
DEBUGASSERT(ret >= 0);

ret = file_dup3(filep, filep2, flags);
fs_putfilep(filep2);
if (ret >= 0)
{
file_close(&filep2);
return fd2;
}

return fd2;
fs_putfilep(filep2);
return ret;
}

/****************************************************************************
Expand Down

0 comments on commit 5b889b9

Please sign in to comment.