fs/inode/fs_files.c
/****************************************************************************
 * Name: nx_dup2
 *
 * Description:
 *   nx_dup2() is similar to the standard 'dup2' interface except that is
 *   not a cancellation point and it does not modify the errno variable.
 *
 *   nx_dup2() is an internal NuttX interface and should not be called from
 *   applications.
 *
 *   Clone a file descriptor to a specific descriptor number.
 *
 * Returned Value:
 *   fd2 is returned on success; a negated errno value is return on
 *   any failure.
 *
 ****************************************************************************/
nx_dup2
Description:
nx_dup2() is similar to the standard 'dup2' interface except that is
not a cancellation point and it does not modify the errno variable.

nx_dup2() is an internal NuttX interface and should not be called from
applications.

Clone a file descriptor to a specific descriptor number.

Returned Value:
fd2 is returned on success; a negated errno value is return on
any failure.
nx_dup2 Description : nx_dup2 () is similar to the standard ' dup2 ' interface except that is not a cancellation point and it does not modify the errno variable . nx_dup2 () is an internal NuttX interface and should not be called from applications . Clone a file descriptor to a specific descriptor number . Returned Value : fd2 is returned on success ; a negated errno value is return on any failure .
int nx_dup2(int fd1, int fd2)
{
  FAR struct filelist *list;
  int ret;
  if (fd1 < 0 || fd1 >= CONFIG_NFILE_DESCRIPTORS ||
      fd2 < 0 || fd2 >= CONFIG_NFILE_DESCRIPTORS)
    {
      return -EBADF;
    }
  list = nxsched_get_files();
  DEBUGASSERT(list != NULL);
  ret = _files_semtake(list);
  if (ret < 0)
    {
      return ret;
    }
  ret = file_dup2(&list->fl_files[fd1], &list->fl_files[fd2]);
  _files_semgive(list);
  if (ret < 0)
    {
      return ret;
    }
  return fd2;
}
int nx_dup2 ( int fd1 , int fd2 ) { FAR struct filelist * list ; int ret ; if ( fd1 < 0 || fd1 >= CONFIG_NFILE_DESCRIPTORS || fd2 < 0 || fd2 >= CONFIG_NFILE_DESCRIPTORS ) { return - EBADF ; } list = nxsched_get_files ( ) ; DEBUGASSERT ( list != NULL ) ; ret = _files_semtake ( list ) ; if ( ret < 0 ) { return ret ; } ret = file_dup2 ( & list -> fl_files [ fd1 ] , & list -> fl_files [ fd2 ] ) ; _files_semgive ( list ) ; if ( ret < 0 ) { return ret ; } return fd2 ; }
Name: nx_dup2
 Description:
   nx_dup2() is similar to the standard 'dup2' interface except that is
   not a cancellation point and it does not modify the errno variable.
Name : nx_dup2 Description : nx_dup2 () is similar to the standard ' dup2 ' interface except that is not a cancellation point and it does not modify the errno variable .
/* Get the file descriptor list.  It should not be NULL in this context. */ /* Probably canceled */ /* Perform the dup2 operation */