All rights reserved. The Berkeley software License Agreement
specifies the terms and conditions for redistribution.
@(#)dup.2 6.3 (Berkeley) 05/13/86
newd = dup(oldd) int newd, oldd;dup2(oldd, newd) int oldd, newd;
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 (2) and lseek (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 open (2) call. The close-on-exec flag on the new file descriptor is unset.
In the second form of the call, the value of newd 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.
15 [EBADF] Oldd or newd is not a valid active descriptor
15 [EMFILE] Too many descriptors are active.