posix_spawn_file_actions_adddup2 Subroutine

Purpose

Adds dup2 action to the spawn file actions object.

Syntax

#include <spawn.h>
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *
       file_actions, int fildes, int newfildes); 

Description

The posix_spawn_file_actions_adddup2 subroutine adds a dup2 action to the object referenced by file_actions that causes the file descriptor fildes to be duplicated as newfildes when a new process is spawned using this file actions object. This functions as if dup2( fildes, newfildes) had been called.

A spawn file actions object is as defined in posix_spawn_file_actions_addclose.

Return Values

Upon successful completion, the posix_spawn_file_actions_adddup2 subroutine returns 0; otherwise, an error number is returned to indicate the error.

Error Codes

The posix_spawn_file_actions_adddup2 subroutine will fail if the following are true:
Item Description
EBADF The value specified by fildes or newfildes is negative, or greater than or equal to {OPEN_MAX}.
ENOMEM Insufficient memory exists to add to the spawn file actions object.
The posix_spawn_file_actions_adddup2 subroutine might fail if the following is true:
Item Description
EINVAL The value specified by file_actions is invalid.

It is not an error for the fildes argument passed to this subroutine to specify a file descriptor for which the specified operation could not be performed at the time of the call. Any such error will be detected when the associated file actions object is used later during a posix_spawn or posix_spawnp operation.