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

dup2(2) OSS System Calls Ref
erence Manual
NAME
dup2 - Duplicates and controls an open le descriptor
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <unistd.h>
int dup2(
int ledes,
int new);
PARAMETERS
filedes Species an open le descriptor obtained from a successful call to the accept(),
creat(), dup( ), dup2( ), fcntl( ), open(), pipe( ), socket(),orsocketpair() func-
tion.
new Species the open le descriptor that is returned by the dup2() function. If this
descriptor is already in use, it is rst deallocated as if it had been closed.
DESCRIPTION
The dup2( ) function returns a new le descriptor on the open le specied by the ledes parame-
ter. If new is less than 0 (zero) or greater than or equal to the maximum number of opens permit-
ted, dup2( ) returns -1 with errno set to [EBADF].
The new le descriptor:
Is the value specied as the new parameter:
If ledes is a valid le descriptor and is equal to new, dup2( ) returns new
without closing it.
If ledes is not a valid le descriptor, dup2( ) returns -1 and does not close new.
The value returned is equal to the value of new upon successful completion, or it
is -1 upon failure.
References the same open
Returns the same le pointer as the original le (that is, both le descriptors share one
le pointer if the object is a le)
Returns the same access mode (read, write, or read/write)
Returns the same le status ags (that is, both le descriptors share the same le status
ags)
Clears the close-on-exec ag (FD_CLOEXEC bit) associated with the new le descrip-
tor so that the le remains open across calls to any function in the exec, tdm_exec, and
tdm_spawn sets of functions
140 Hewlett-Packard Company 527186-003