posix_spawn_file_actions_adddup2()

Add a “duplicate a file descriptor” action to a spawn file actions object

Synopsis:

#include <spawn.h>

int posix_spawn_file_actions_adddup2(
       posix_spawn_file_actions_t *fact_p,
       int fd,
       int new_fd);

Arguments:

fact_p
A pointer to the spawn file actions object that you want to update. You must have already initialized this object by calling posix_spawn_file_actions_init().
fd
The file descriptor that you want to duplicate.
new_fd
The number that you want to use for the new file descriptor.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The posix_spawn_file_actions_adddup2() function adds a dup2() action to the object referenced by fact_p that causes the file descriptor fd to be duplicated as new_fd (as if a call were made to dup2(fd, new_fd)) when a new process is spawned using this file actions object.

Returns:

EOK
Success.
EBADF
The value specified by fd or new_fd is negative or greater than or equal to {OPEN_MAX}.
EINVAL
An argument was invalid. The value specified by file actions is invalid.
ENOMEM
The action couldn't be added to the file actions object, or insufficient memory exists to add to the spawn file actions object.

It isn't considered an error for the fd argument to specify a file descriptor for which the specified operation couldn't be performed at the time of the call. Any such error will be detected when the associated file actions object is later used during a posix_spawn() or posix_spawnp() operation.

Classification:

POSIX 1003.1 SPN

Safety:  
Cancellation point No
Interrupt handler Yes
Signal handler Yes
Thread Yes