DUP(S) XENIX System V DUP(S)
Name
dup, dup2 - Duplicates an open file descriptor.
Syntax
int dup (fildes)
int fildes;
int dup2(fildes, fildes2)
int fildes, fildes2;
Description
fildes is a file descriptor obtained from a creat, open,
dup, fcntl, or pipe system call. dup 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(S).
dup returns the lowest available file descriptor. dup2
causes fildes2 to refer to the same file as fildes. If
fildes2 already referred to an open file, it is closed
first.
dup will fail if one or more of the following are true:
fildes is not a valid open file descriptor. [EBADF]
Sixty file descriptors are currently open. [EMFILE]
Return Value
Upon successful completion a nonnegative integer, namely the
file descriptor, is returned. Otherwise, a value of -1 is
returned and errno is set to indicate the error.
Notes
This routine must be linked using the linker option -lx.
See Also
creat(S), close(S), exec(S), fcntl(S), open(S), pipe(S)
Page 1 (printed 8/7/87)