dup2(3N) dup2(3N)
NAME
dup2 - duplicate a descriptor
SYNOPSIS
dup2(oldd, newd)
int oldd, newd;
DESCRIPTION
dup2 causes newd to become a duplicate of oldd. If newd is
already in use, the descriptor is first deallocated as if a
close(2) call had been done first.
The object referenced by the descriptor does not distinguish
between references using oldd and newd in any way. Thus if
newd and oldd are duplicate references to an open file,
read(2), write(3), and lseek(2) calls all move a single
pointer into the file. If a separate pointer into the file
is desired, a different object reference to the file must be
obtained by issuing an additional open(2) call.
RETURN VALUE
The value -1 is returned if an error occurs in either call.
The external variable errno indicates the cause of the
error.
ERRORS
dup2 fails if:
[EBADF]
oldd or newd is not a valid active descriptor
[EMFILE]
Too many descriptors are active.
SEE ALSO
accept(2N), open(2), close(2), pipe(2), socket(2N),
getdtablesize(3N).
Page 1 (last mod. 1/14/87)