DUP(2) INTERACTIVE UNIX System DUP(2)
NAME
dup - duplicate an open file descriptor
SYNOPSIS
int dup (fildes)
int fildes;
DESCRIPTION
The fildes argument is a file descriptor obtained from a
creat, open, dup, fcntl, or pipe system call. The dup sys-
tem call returns a new file descriptor having the following
in common with the original:
Same open file (or pipe)
Same file pointer (i.e., both file descriptors share
one file pointer)
Same access mode (read, write, or read/write)
The new file descriptor is set to remain open across exec
system calls [see fcntl(2)].
The file descriptor returned is the lowest one available.
The dup system call will fail if one or more of the follow-
ing is true:
[EBADF] The fildes argument is not a valid open file
descriptor.
[EINTR] A signal was caught during the dup system
call.
[EMFILE] NOFILES file descriptors are currently open.
[ENOLINK] Fildes is on a remote machine and the link to
that machine is no longer active.
SEE ALSO
close(2), creat(2), exec(2), fcntl(2), open(2), pipe(2),
lockf(3C).
DIAGNOSTICS
Upon successful completion a non-negative integer, namely
the file descriptor, is returned. Otherwise, a value of -1
is returned, and errno is set to indicate the error.
Rev. C Software Development Set Page 1