SYNOPSIS
#include <unistd.h>
int dup(int fildes, int fildes2);
DESCRIPTION
The
On success,
- 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
The call:
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
OPEN_MAX, the
dup2() function returns a value of -1 and sets errno to EBADF. -
If fildes is a valid file descriptor and is equal to
fildes2, the
dup2() function returns fildes2 without closing it. -
If fildes is not a valid file descriptor,
dup2() fails and does not close fildes2. -
If successful,
dup2() returns a value that is equal to the value of fildes2. If a failure occurs, it returns a value of -1.
PARAMETERS
- fildes
-
Is the file descriptor to duplicate.
- fildes2
-
Is the file descriptor that fildes is duplicated onto.
RETURN VALUES
If successful,
- EBADF
-
fildes is not a valid open file descriptor.
- EINTR
-
A signal was caught during the
dup2() system call. - EMFILE
-
The number of file descriptors exceeds OPEN_MAX.
CONFORMANCE
POSIX.1 (1996)
MULTITHREAD SAFETY LEVEL
Async-signal-safe.
PORTING ISSUES
None.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
close() ,creat() ,dup() ,execl() ,execle() ,execlp() ,execlpe() ,execv() ,execve() ,execvp() ,execvpe() ,fcntl() ,lockf() ,open() ,pipe() ,socket()
PTC MKS Toolkit 10.5 Documentation Build 40.