diff --git a/fs/inode/fs_files.c b/fs/inode/fs_files.c index af466e8f99..6d549d2313 100644 --- a/fs/inode/fs_files.c +++ b/fs/inode/fs_files.c @@ -188,6 +188,11 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2) return -EBADF; } + if (filep1 == filep2) + { + return OK; + } + list = nxsched_get_files(); /* The file list can be NULL under two cases: (1) One is an obscure diff --git a/fs/vfs/fs_dupfd.c b/fs/vfs/fs_dupfd.c index 5364bdef93..c3525ae79d 100644 --- a/fs/vfs/fs_dupfd.c +++ b/fs/vfs/fs_dupfd.c @@ -32,12 +32,6 @@ #include "inode/inode.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DUP_ISOPEN(filep) (filep->f_inode != NULL) - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -61,14 +55,7 @@ int file_dup(FAR struct file *filep, int minfd) int fd2; int ret; - /* Verify that fd is a valid, open file descriptor */ - - if (!DUP_ISOPEN(filep)) - { - return -EBADF; - } - - /* Then allocate a new file descriptor for the inode */ + /* Allocate a new file descriptor for the inode */ fd2 = files_allocate(NULL, 0, 0, minfd); if (fd2 < 0) diff --git a/fs/vfs/fs_dupfd2.c b/fs/vfs/fs_dupfd2.c index d314a224ac..3ad7aa0c28 100644 --- a/fs/vfs/fs_dupfd2.c +++ b/fs/vfs/fs_dupfd2.c @@ -46,16 +46,6 @@ #include "inode/inode.h" -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define DUP_ISOPEN(filep) (filep->f_inode != NULL) - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -93,20 +83,6 @@ int fs_dupfd2(int fd1, int fd2) DEBUGASSERT(filep1 != NULL && filep2 != NULL); - /* Verify that fd1 is a valid, open file descriptor */ - - if (!DUP_ISOPEN(filep1)) - { - return -EBADF; - } - - /* Handle a special case */ - - if (fd1 == fd2) - { - return fd1; - } - /* Perform the dup2 operation */ return file_dup2(filep1, filep2);