anchao commented on code in PR #11177:
URL: https://github.com/apache/nuttx/pull/11177#discussion_r1393013541


##########
sched/task/task_spawnparms.c:
##########
@@ -289,3 +291,70 @@ int spawn_file_actions(FAR struct tcb_s *tcb,
 
   return ret;
 }
+
+/****************************************************************************
+ * Name: spawn_file_is_duplicateable
+ *
+ * Description:
+ *   Check the input file descriptor is duplicateable from spawn actions
+ *
+ * Input Parameters:
+ *
+ *   actions - The spawn file actions
+ *   fd      - file descriptor
+ *
+ * Returned Value:
+ *   Return 1 if file descriptor is duplicate able
+ *   Return 0 if file descriptor in action list but unable to duplicate
+ *   Return -1 if file descriptor without in actions list
+ *
+ ****************************************************************************/
+
+int
+spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions,
+                            int fd)
+{
+  FAR struct spawn_general_file_action_s *entry;
+  FAR struct spawn_close_file_action_s *close;
+  FAR struct spawn_open_file_action_s *open;
+  FAR struct spawn_dup2_file_action_s *dup2;
+
+  /* Execute each file action */
+
+  for (entry = (FAR struct spawn_general_file_action_s *)actions;
+       entry != NULL;
+       entry = entry->flink)
+    {
+      switch (entry->action)
+        {
+          case SPAWN_FILE_ACTION_CLOSE:
+            close = (FAR void *)entry;

Review Comment:
   Done



##########
sched/task/task_spawnparms.c:
##########
@@ -289,3 +291,70 @@ int spawn_file_actions(FAR struct tcb_s *tcb,
 
   return ret;
 }
+
+/****************************************************************************
+ * Name: spawn_file_is_duplicateable
+ *
+ * Description:
+ *   Check the input file descriptor is duplicateable from spawn actions
+ *
+ * Input Parameters:
+ *
+ *   actions - The spawn file actions
+ *   fd      - file descriptor
+ *
+ * Returned Value:
+ *   Return 1 if file descriptor is duplicate able
+ *   Return 0 if file descriptor in action list but unable to duplicate
+ *   Return -1 if file descriptor without in actions list
+ *
+ ****************************************************************************/
+
+int
+spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions,
+                            int fd)
+{
+  FAR struct spawn_general_file_action_s *entry;
+  FAR struct spawn_close_file_action_s *close;
+  FAR struct spawn_open_file_action_s *open;
+  FAR struct spawn_dup2_file_action_s *dup2;
+
+  /* Execute each file action */
+
+  for (entry = (FAR struct spawn_general_file_action_s *)actions;
+       entry != NULL;
+       entry = entry->flink)
+    {
+      switch (entry->action)
+        {
+          case SPAWN_FILE_ACTION_CLOSE:
+            close = (FAR void *)entry;
+            if (close->fd == fd)
+              {
+                return 0;
+              }
+            break;
+
+          case SPAWN_FILE_ACTION_DUP2:
+            dup2 = (FAR void *)entry;

Review Comment:
   Done



##########
sched/task/task_spawnparms.c:
##########
@@ -289,3 +291,70 @@ int spawn_file_actions(FAR struct tcb_s *tcb,
 
   return ret;
 }
+
+/****************************************************************************
+ * Name: spawn_file_is_duplicateable
+ *
+ * Description:
+ *   Check the input file descriptor is duplicateable from spawn actions
+ *
+ * Input Parameters:
+ *
+ *   actions - The spawn file actions
+ *   fd      - file descriptor
+ *
+ * Returned Value:
+ *   Return 1 if file descriptor is duplicate able
+ *   Return 0 if file descriptor in action list but unable to duplicate
+ *   Return -1 if file descriptor without in actions list
+ *
+ ****************************************************************************/
+
+int
+spawn_file_is_duplicateable(FAR const posix_spawn_file_actions_t *actions,
+                            int fd)
+{
+  FAR struct spawn_general_file_action_s *entry;
+  FAR struct spawn_close_file_action_s *close;
+  FAR struct spawn_open_file_action_s *open;
+  FAR struct spawn_dup2_file_action_s *dup2;
+
+  /* Execute each file action */
+
+  for (entry = (FAR struct spawn_general_file_action_s *)actions;
+       entry != NULL;
+       entry = entry->flink)
+    {
+      switch (entry->action)
+        {
+          case SPAWN_FILE_ACTION_CLOSE:
+            close = (FAR void *)entry;
+            if (close->fd == fd)
+              {
+                return 0;
+              }
+            break;
+
+          case SPAWN_FILE_ACTION_DUP2:
+            dup2 = (FAR void *)entry;
+            if (dup2->fd1 == fd)
+              {
+                return 1;
+              }
+            break;
+
+          case SPAWN_FILE_ACTION_OPEN:
+            open = (FAR void *)entry;

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