2013-01-09 22:31:36 +01:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* libs/libc/spawn/lib_psfa_adddup2.c
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
2021-03-02 15:54:21 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-01-09 22:31:36 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <spawn.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2013-01-18 02:52:42 +01:00
|
|
|
#include <nuttx/spawn.h>
|
2013-01-09 22:31:36 +01:00
|
|
|
|
2015-12-30 00:31:17 +01:00
|
|
|
#include "libc.h"
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2013-01-09 22:31:36 +01:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Functions
|
2013-01-09 22:31:36 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: posix_spawn_file_actions_adddup2
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The posix_spawn_file_actions_adddup2() function adds a dup2 operation to
|
|
|
|
* the list of operations associated with the object referenced by
|
2013-01-10 01:45:11 +01:00
|
|
|
* file_actions, for subsequent use in a call to posix_spawn() or
|
|
|
|
* posix_spawnp(). The descriptor referred to by fd2 is created as
|
2013-01-09 22:31:36 +01:00
|
|
|
* if dup2() had been called on fd1 prior to the new child process
|
|
|
|
* starting execution.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* file_actions - The posix_spawn_file_actions_t to append the action.
|
|
|
|
* fd1 - The first file descriptor to be argument to dup2.
|
|
|
|
* fd2 - The first file descriptor to be argument to dup2.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, these functions return 0; on failure they return an error
|
|
|
|
* number from <errno.h>.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-02 14:33:27 +01:00
|
|
|
int posix_spawn_file_actions_adddup2(
|
|
|
|
FAR posix_spawn_file_actions_t *file_actions,
|
|
|
|
int fd1, int fd2)
|
2013-01-09 22:31:36 +01:00
|
|
|
{
|
|
|
|
FAR struct spawn_dup2_file_action_s *entry;
|
|
|
|
|
2021-03-16 13:13:02 +01:00
|
|
|
DEBUGASSERT(file_actions && fd1 >= 0 && fd2 >= 0);
|
2013-01-09 22:31:36 +01:00
|
|
|
|
|
|
|
/* Allocate the action list entry */
|
|
|
|
|
|
|
|
entry = (FAR struct spawn_dup2_file_action_s *)
|
2013-03-09 22:12:20 +01:00
|
|
|
lib_zalloc(sizeof(struct spawn_close_file_action_s));
|
2013-01-09 22:31:36 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2021-03-02 14:33:27 +01:00
|
|
|
add_file_action(file_actions,
|
|
|
|
(FAR struct spawn_general_file_action_s *)entry);
|
2013-01-09 22:31:36 +01:00
|
|
|
return OK;
|
|
|
|
}
|