BSD 4_3_Tahoe development
[unix-history] / usr / man / cat2 / dup.0
DUP(2) UNIX Programmer's Manual DUP(2)
N\bNA\bAM\bME\bE
dup, dup2 - duplicate a descriptor
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
n\bne\bew\bwd\bd =\b= d\bdu\bup\bp(\b(o\bol\bld\bdd\bd)\b)
i\bin\bnt\bt n\bne\bew\bwd\bd,\b, o\bol\bld\bdd\bd;\b;
d\bdu\bup\bp2\b2(\b(o\bol\bld\bdd\bd,\b, n\bne\bew\bwd\bd)\b)
i\bin\bnt\bt o\bol\bld\bdd\bd,\b, n\bne\bew\bwd\bd;\b;
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
_\bD_\bu_\bp duplicates an existing object descriptor. The argument
_\bo_\bl_\bd_\bd is a small non-negative integer index in the per-
process descriptor table. The value must be less than the
size of the table, which is returned by _\bg_\be_\bt_\bd_\bt_\ba_\bb_\bl_\be_\bs_\bi_\bz_\be(2).
The new descriptor returned by the call, _\bn_\be_\bw_\bd, is the lowest
numbered descriptor that is not currently in use by the pro-
cess.
The object referenced by the descriptor does not distinguish
between references using _\bo_\bl_\bd_\bd and _\bn_\be_\bw_\bd in any way. Thus if
_\bn_\be_\bw_\bd and _\bo_\bl_\bd_\bd are duplicate references to an open file,
_\br_\be_\ba_\bd(2), _\bw_\br_\bi_\bt_\be(2) and _\bl_\bs_\be_\be_\bk(2) calls all move a single
pointer into the file, and append mode, non-blocking I/O and
asynchronous I/O options are shared between the references.
If a separate pointer into the file is desired, a different
object reference to the file must be obtained by issuing an
additional _\bo_\bp_\be_\bn(2) call. The close-on-exec flag on the new
file descriptor is unset.
In the second form of the call, the value of _\bn_\be_\bw_\bd desired is
specified. If this descriptor is already in use, the
descriptor is first deallocated as if a _\bc_\bl_\bo_\bs_\be(2) call had
been done first.
R\bRE\bET\bTU\bUR\bRN\bN V\bVA\bAL\bLU\bUE\bE
The value -1 is returned if an error occurs in either call.
The external variable _\be_\br_\br_\bn_\bo indicates the cause of the
error.
E\bER\bRR\bRO\bOR\bRS\bS
_\bD_\bu_\bp and _\bd_\bu_\bp_\b2 fail if:
[EBADF] _\bO_\bl_\bd_\bd or _\bn_\be_\bw_\bd is not a valid active descriptor
[EMFILE] Too many descriptors are active.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
accept(2), open(2), close(2), fcntl(2), pipe(2), socket(2),
socketpair(2), getdtablesize(2)
Printed 7/9/88 May 13, 1986 1