dup(2) dup(2)NAME dup - duplicates a descriptor SYNOPSIS int dup(oldd) int oldd; DESCRIPTION dup duplicates an existing object descriptor. The argument oldd 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(2N). The new descriptor 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 the old and new descriptor in any way. Thus, if the old and new descriptor 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. STATUS MESSAGES AND VALUES The value -1 is returned if an error occurs in either call and errno is set to indicate the error. The dup command fails if: EBADF The old descriptor is not a valid active descriptor EMFILE Too many descriptors are active. SEE ALSO accept(2N), open(2), close(2), getdtablesize(2N), pipe(2), socket(2N), dup2(3N) January 1992 1