|
NAMEdup , dup2 —
duplicate an existing file descriptor
LIBRARYStandard C Library (libc, -lc)SYNOPSIS#include <unistd.h>
int
int
DESCRIPTIONThedup () system call duplicates an existing object
descriptor and returns its value to the calling process
(newd =
dup (oldd)). The argument
oldd is a small non-negative integer index in the
per-process descriptor table. The new descriptor returned by the call is the
lowest numbered descriptor currently not in use by the process.
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) system call. The close-on-exec flag on the new file descriptor is unset. In RETURN VALUESThese calls return the new file descriptor if successful; otherwise the value -1 is returned and the external variable errno is set to indicate the cause of the error.ERRORSThedup () system call fails if:
The
SEE ALSOaccept(2), close(2), fcntl(2), getdtablesize(2), open(2), pipe(2), socket(2), socketpair(2), dup3(3)STANDARDSThedup () and dup2 () system
calls are expected to conform to IEEE Std 1003.1-1990
(“POSIX.1”).
HISTORYThedup () function appeared in
Version 3 AT&T UNIX. The
dup2 () function appeared in
Version 7 AT&T UNIX.
Visit the GSP FreeBSD Man Page Interface. |