pussuw commented on code in PR #16361:
URL: https://github.com/apache/nuttx/pull/16361#discussion_r2086066759


##########
fs/inode/fs_files.c:
##########
@@ -246,6 +303,85 @@ static void task_fssync(FAR struct tcb_s *tcb, FAR void 
*arg)
     }
 }
 
+/****************************************************************************
+ * Name: fs_closefilep
+ *
+ * Description:
+ *   Close an existing file pointer and free the allocated memory.
+ *
+ * Input Parameters:
+ *   filep - The file pointer.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int fs_closefilep(FAR struct file *filep)
+{
+  int ret;
+
+  ret = file_close(filep);
+  if (ret >= 0)
+    {
+      fs_heap_free(filep);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: nx_dup2_from_tcb
+ *
+ * Description:
+ *   nx_dup2_from_tcb() is similar to the standard 'dup2' interface
+ *   except that is not a cancellation point and it does not modify the
+ *   errno variable.
+ *
+ *   nx_dup2_from_tcb() 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_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2)
+{
+  /* If fd1 is a valid file descriptor, and fd1 == fd2, then dup2() does
+   * nothing, and returns fd2.
+   */
+
+  if (fd1 == fd2)
+    {

Review Comment:
   No, this is correct, we must handle fd1==fd2 differently for dup2 and dup3
   
   dup2(): `unless fildes is equal to fildes2 in which case dup2() shall return 
fildes2 without closing it. `
   dup3(): `The dup3() function shall be equivalent to the dup2() function, 
except that it shall be an error if fildes is equal to fildes2,`
   
   https://pubs.opengroup.org/onlinepubs/9799919799/functions/dup.html
   



##########
fs/inode/fs_files.c:
##########
@@ -246,6 +303,85 @@ static void task_fssync(FAR struct tcb_s *tcb, FAR void 
*arg)
     }
 }
 
+/****************************************************************************
+ * Name: fs_closefilep
+ *
+ * Description:
+ *   Close an existing file pointer and free the allocated memory.
+ *
+ * Input Parameters:
+ *   filep - The file pointer.
+ *
+ * Returned Value:
+ *   Zero (OK) is returned on success; a negated errno value is returned on
+ *   any failure.
+ *
+ ****************************************************************************/
+
+int fs_closefilep(FAR struct file *filep)
+{
+  int ret;
+
+  ret = file_close(filep);
+  if (ret >= 0)
+    {
+      fs_heap_free(filep);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: nx_dup2_from_tcb
+ *
+ * Description:
+ *   nx_dup2_from_tcb() is similar to the standard 'dup2' interface
+ *   except that is not a cancellation point and it does not modify the
+ *   errno variable.
+ *
+ *   nx_dup2_from_tcb() 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_from_tcb(FAR struct tcb_s *tcb, int fd1, int fd2)
+{
+  /* If fd1 is a valid file descriptor, and fd1 == fd2, then dup2() does
+   * nothing, and returns fd2.
+   */
+
+  if (fd1 == fd2)
+    {

Review Comment:
   No, this is correct, we must handle fd1==fd2 differently for dup2 and dup3
   
   dup2(): `unless fildes is equal to fildes2 in which case dup2() shall return 
fildes2 without closing it. `
   
   dup3(): `The dup3() function shall be equivalent to the dup2() function, 
except that it shall be an error if fildes is equal to fildes2,`
   
   https://pubs.opengroup.org/onlinepubs/9799919799/functions/dup.html
   



-- 
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