Duplicates an open file descriptor.
Syntax |
 |
#include <unistd.h>
int dup (int fildes);
int dup2(iint fildes, int fildes2)
|
Parameters |
 |
- fildes
An open file descriptor.
Return Values |
 |
- >=0
Success. A new file descriptor is returned.
- -1
An error occurred. the open file descriptor is not duplicated, and errno is set to indicate the error condition.
Description |
 |
The dup() and dup2 functions return the lowest numbered file descriptor not currentely open by the calling process. The file descriptors returned by dup() and dup2() refer to the same open file description as fildes and share any locks.
The dup() and dup2() functions ignore file access permission bits when attempting to duplicate an open file descriptor.
Implementation Considerations |
 |
Refer to the EEXCL and ESYSERR error descriptions below.
Signals generated for the calling process during execution of dup() re deferred from delivery until completion of this function.
Errors |
 |
If an error occurs, errno is set to one of the following values:
See Also |
 |
close(), creat(), execl(), execv(), open(), POSIX.1 (Section 6.2.1)