Open System Services System Calls Reference Manual (G06.25+, H06.03+)

System Functions (a - d) dup2(2)
NOTES
The dup2( ) function provides an alternative interface to the service provided by the fcntl( ) func-
tion by using the F_DUPFD value of the request parameter. The call:
fid = dup2( file1, file2 );
is equivalent to:
close( file2 );
fid = fcntl( file1, F_DUPFD, file2 );
RETURN VALUES
Upon successful completion, the dup2() function returns a new le descriptor. Otherwise, the
value -1 is returned, and errno is set to indicate the error.
ERRORS
If any of these conditions occurs, the dup2() function sets errno to the corresponding value:
[EBADF] One of these conditions exists:
The ledes parameter is not a valid open le descriptor.
The new parameter le descriptor is negative or greater than the max-
imum number of opens permitted.
[EISGUARDIAN]
The value used for the ledes parameter is appropriate only in the Guardian
environment.
[EWRONGID] One of these conditions occurred:
The process attempted an operation on an input/output process (such as a
terminal server process) that has failed or is in the down state.
The processor for the disk process of the specied le failed during an
input or output operation, and takeover by the backup process occurred.
The open le descriptor has migrated to a new processor, but the new
processor lacks a resource or system process needed for using the le
descriptor.
The le descriptor specied by the ledes parameter can only be closed.
For all other error conditions, errno is set to the appropriate Guardian le-system error number.
See the Guardian Procedure Errors and Messages Manual for more information about a specic
Guardian le-system error.
RELATED INFORMATION
Functions: close(2), dup(2), exec(2), fcntl(2), open(2), read(2), tdm_execve(2),
tdm_execvep(2), write(2).
STANDARDS CONFORMANCE
The dup2( ) function does not return the errno value [EINTR].
HP extensions to the XPG4 Version 2 specication are:
The errno values [EISGUARDIAN] and [EWRONGID] can be returned.
527186-003 Hewlett-Packard Company 141