Donny9 commented on code in PR #16499:
URL: https://github.com/apache/nuttx/pull/16499#discussion_r2136838430


##########
fs/inode/fs_files.c:
##########
@@ -258,70 +292,43 @@ static void task_fssync(FAR struct tcb_s *tcb, FAR void 
*arg)
  *
  ****************************************************************************/
 
-int nx_dup3_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2, int flags)
+int fdlist_dup3(FAR struct fdlist *list, int fd1, int fd2, int flags)
 {
-  FAR struct filelist *list;
   FAR struct file *filep1;
-  FAR struct file *filep;
-  bool new = false;
-  int count;
   int ret;
 
   if (fd1 == fd2)
     {
-      return fd1;
+      return -EINVAL;
     }
 
 #ifdef CONFIG_FDCHECK
-  fd1 = fdcheck_restore(fd1);
   fd2 = fdcheck_restore(fd2);
 #endif
 
   /* Get the file descriptor list.  It should not be NULL in this context. */
 
-  list = nxsched_get_files_from_tcb(tcb);
-  count = files_countlist(list);
-
-  if (fd1 < 0 || fd1 >= count || fd2 < 0)
+  if (fd2 < 0)
     {
       return -EBADF;
     }
 
-  if (fd2 >= count)
-    {
-      ret = files_extend(list, fd2 / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + 1);
-      if (ret < 0)
-        {
-          return ret;
-        }
-    }
-
-  filep1 = files_fget(list, fd1);
-  if (filep1 == NULL)
+  ret = fdlist_extend(list,

Review Comment:
   Done ~



##########
fs/inode/fs_files.c:
##########
@@ -587,37 +618,120 @@ int file_allocate_from_tcb(FAR struct tcb_s *tcb, FAR 
struct inode *inode,
 #endif
 }
 
+/****************************************************************************
+ * Name: fdlist_allocate
+ *
+ * Description:
+ *   Allocate a struct fd instance and associate it with an empty file
+ *   instance. The difference between this function and
+ *   file_allocate_from_inode is that this function is only used for
+ *   placeholder purposes. Later, the caller will initialize the file entity
+ *   through the returned filep.
+ *
+ *   The fd allocated by this function can be released using fdlist_close.
+ *
+ * Returned Value:
+ *   Returns the file descriptor == index into the files array on success;
+ *   a negated errno value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int fdlist_allocate(FAR struct fdlist *list, int oflags,
+                    int minfd, FAR struct file **filep)
+{
+  int fd;
+
+  *filep = fs_heap_zalloc(sizeof(struct file));
+  if (*filep == NULL)
+    {
+      return -ENOMEM;
+    }
+
+  fd = fdlist_dupfile(list, oflags, minfd, *filep);
+  if (fd < 0)

Review Comment:
   Done ~



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to