Open System Services System Calls Reference Manual (G06.29+, H06.08+, J06.03+)

dup2(2) OSS System Calls Reference Manual
NAME
dup2 - Duplicates and controls an open file descriptor
LIBRARY
G-series native OSS processes: system library
H-series and J-series OSS processes: implicit libraries
32-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/zputdll
64-bit H-series and J-series OSS processes that use the POSIX User Thread Model library:
/G/system/zdllnnn/yputdll
SYNOPSIS
#include <unistd.h>
int dup2(
int filedes,
int new);
PARAMETERS
filedes Specifies an open file descriptor obtained from a successful call to the accept(),
creat(), dup( ), dup2( ), fcntl(), open(), pipe(), socket(),orsocketpair() func-
tion.
When the function is thread-aware, specifies an open file descriptor obtained
from a successful call to the creat(), creat64(), dup(), open(), open64(),
pipe( ), socket(),orsocketpair() function, or the thread-aware accept(),
dup2( ),orfcntl( ) function.
new Specifies the open file descriptor that is returned by the dup2() function. If this
descriptor is already in use, it is first deallocated as if it had been closed.
DESCRIPTION
The dup2( ) function returns a new file descriptor on the open file specified by the filedes 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 file descriptor:
Is the value specified as the new parameter:
—Iffiledes is a valid file descriptor and is equal to new, dup2() returns new
without closing it.
—Iffiledes is not a valid file 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 file pointer as the original file (that is, both file descriptors share one
file pointer if the object is a file).
Returns the same access mode (read, write, or read/write).
160 Hewlett-Packard Company 527186-023