DUP(2) COMMAND REFERENCE DUP(2)
NAME
dup, dup2 - duplicate a descriptor
SYNOPSIS
newfd = dup(oldfd)
int newfd, oldfd;
newfd = dup2(oldfd, newfd)
int oldfd, newfd;
DESCRIPTION
Dup duplicates an existing object descriptor. The argument
oldfd 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 getdtablesize(2).
The new descriptor newfd returned by the call is the lowest
numbered descriptor which is not currently in use by the
process.
The object referenced by the descriptor does not distinguish
between references using oldfd and newfd in any way. Thus
if newfd and oldfd are duplicate references to an open file,
read(2), write(2) 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.
In the second form of the call, the value of newfd desired
is specified. If this descriptor is already in use, the
descriptor is first deallocated as if a close(2) call had
been done first.
DIAGNOSTICS
Dup and dup2 fail if:
[EBADF]
Oldfd or newfd is not a valid active descriptor.
[EMFILE]
NOFILE (defined in <sys/max.h>) descriptors are already
active.
RETURN VALUE
Upon successful completion, dup and dup2 return the new file
descriptor in newfd. Otherwise, a value of -1 is returned
and errno is set to indicate the error.
SEE ALSO
accept(2), close(2), getdtablesize(2), open(2), pipe(2),
socket(2), socketpair(2).
Printed 10/17/86 1
%%index%%
na:72,70;
sy:142,575;
de:717,1286;
di:2003,337;
rv:2340,317;
se:2657,256;
%%index%%000000000107