DUP(2) | NetBSD System Calls Manual | DUP(2) |
int
dup(int oldd);
int
dup2(int oldd, int newd);
int
dup3(int oldd, int newd, int flags);
The object referenced by the descriptor does not distinguish between 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 dup2(), the value of the new descriptor newd is specified. If this descriptor is already in use, the descriptor is first deallocated as if a close(2) call had been done first. If newd and oldd are the same, the call has no effect.
dup3() behaves exactly like dup2() only it allows extra flags to be set on the returned file descriptor. The following flags are valid:
The dup() function may also fail if:
The dup3() function will also fail if:
July 16, 2011 | NetBSD 5.99 |