int dup(int fildes, int fildes2);
- Same open file (or pipe)
- Same file pointer (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
fid = dup2(fildes, fildes2);
is equivalent to:
close(fildes2); fid = fcntl(fildes, F_DUPFD, fildes2);
with the following exceptions:
If fildes2 is negative or greater than or equal to
dup2()function returns a value of -1 and sets errno to EBADF.
If fildes is a valid file descriptor and is equal to
dup2()function returns fildes2 without closing it.
If fildes is not a valid file descriptor,
dup2()fails and does not close fildes2.
dup2()returns a value that is equal to the value of fildes2. If a failure occurs, it returns a value of -1.
Is the file descriptor to duplicate.
Is the file descriptor that fildes is duplicated onto.
fildes is not a valid open file descriptor.
A signal was caught during the
The number of file descriptors exceeds OPEN_MAX.
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
close(), creat(), dup(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), fcntl(), lockf(), open(), pipe(), socket()
PTC MKS Toolkit 10.0 Documentation Build 6.