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


##########
fs/vfs/fs_fcntl.c:
##########
@@ -347,23 +282,95 @@ int fcntl(int fd, int cmd, ...)
 
   va_start(ap, cmd);
 
-  /* Get the file structure corresponding to the file descriptor. */
-
-  ret = file_get(fd, &filep);
-  if (ret >= 0)
+  switch (cmd)
     {
-      /* Let file_vfcntl() do the real work.  The errno is not set on
-       * failures.
-       */
+      case F_DUPFD:
+        /* Return a new file descriptor which shall be the lowest numbered
+         * available (that is, not already open) file descriptor greater than
+         * or equal to the third argument, arg, taken as an integer of type
+         * int. The new file descriptor shall refer to the same open file
+         * description as the original file descriptor, and shall share any
+         * locks.  The FD_CLOEXEC flag associated  with the new file
+         * descriptor shall be cleared to keep the file open across calls to
+         * one of the exec functions.
+         */
 
-      ret = file_vfcntl(filep, cmd, ap);
-      file_put(filep);
-    }
+        {
+          ret = dup3(fd, va_arg(ap, int), 0);

Review Comment:
   This is wrong, the argument is the smallest fd number requested, NOT the 
exact fd number:
   
   F_DUPFD (int)
                 Duplicate the file descriptor fd using the lowest-numbered
                 available file descriptor greater than or equal to arg.
                 This is different from dup2 which uses exactly the file
                 descriptor specified.
   
   How I wrote it was correct.



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