int posix_spawn_file_actions_adddup2(FAR posix_spawn_file_actions_t *file_actions, int fd1, int fd2) { FAR struct spawn_dup2_file_action_s *entry; DEBUGASSERT(file_actions && fd1 >= 0 && fd1 < CONFIG_NFILE_DESCRIPTORS && fd2 >= 0 && fd2 < CONFIG_NFILE_DESCRIPTORS); /* Allocate the action list entry */ entry = (FAR struct spawn_dup2_file_action_s *) zalloc(sizeof(struct spawn_close_file_action_s)); if (!entry) { return ENOMEM; } /* Initialize the file action entry */ entry->action = SPAWN_FILE_ACTION_DUP2; entry->fd1 = fd1; entry->fd2 = fd2; /* And add it to the file action list */ add_file_action(file_actions, (FAR struct spawn_general_file_action_s *)entry); return OK; }
int posix_spawn_file_actions_addclose(FAR posix_spawn_file_actions_t *file_actions, int fd) { FAR struct spawn_close_file_action_s *entry; DEBUGASSERT(file_actions && fd >= 0 && fd < CONFIG_NFILE_DESCRIPTORS); /* Allocate the action list entry */ entry = (FAR struct spawn_close_file_action_s *) lib_zalloc(sizeof(struct spawn_close_file_action_s)); if (!entry) { return ENOMEM; } /* Initialize the file action entry */ entry->action = SPAWN_FILE_ACTION_CLOSE; entry->fd = fd; /* And add it to the file action list */ add_file_action(file_actions, (FAR struct spawn_general_file_action_s *)entry); return OK; }
/** * @fn : tc_libc_spawn_add_file_action * @brief : Add the file action * @scenario : Add the file action to the end for the file action list * @API's covered : posix_spawn_file_actions_init, posix_spawn_file_actions_addopen, add_file_action * @Preconditions : posix_spawn_file_actions_init,posix_spawn_file_actions_addopen * @Postconditions : posix_spawn_file_actions_destroy * @Return : void */ static void tc_libc_spawn_add_file_action(void) { const char szfilepath[] = "./testdata.txt"; posix_spawn_file_actions_t st_fileactions; struct spawn_open_file_action_s *entry1; struct spawn_open_file_action_s *entry2; size_t length; size_t alloc_num; int ret_chk = ERROR; ret_chk = posix_spawn_file_actions_init(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_init", ret_chk, OK); ret_chk = posix_spawn_file_actions_addopen(&st_fileactions, 1, szfilepath, O_WRONLY, 0644); TC_ASSERT_EQ("posix_spawn_file_actions_addopen", ret_chk, OK); length = strlen(szfilepath); alloc_num = SIZEOF_OPEN_FILE_ACTION_S(length); /* Allocate the action list entry of this size */ entry1 = (struct spawn_open_file_action_s *)zalloc(alloc_num); TC_ASSERT_NOT_NULL("zalloc", entry1); /* And add it to the file action list */ add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry1); entry2 = (struct spawn_open_file_action_s *)zalloc(alloc_num); TC_ASSERT_NOT_NULL("zalloc", entry2); /* And add it to the file action list */ add_file_action(st_fileactions, (struct spawn_general_file_action_s *)entry2); TC_ASSERT_EQ("add_file_action", entry1->flink, (struct spawn_general_file_action_s *)entry2); ret_chk = posix_spawn_file_actions_destroy(&st_fileactions); TC_ASSERT_EQ("posix_spawn_file_actions_destroy", ret_chk, OK); TC_SUCCESS_RESULT(); }