dup()

duplicate open file descriptor 

Function


SYNOPSIS

#include <unistd.h>

int dup(int fildes);


DESCRIPTION

The dup() function duplicates an open file descriptor. Specifically, it provides an alternate interface to the service provided by the fcntl() function using the F_DUPFD constant command value, with 0 for its third argument. The duplicated file descriptor shares any locks with the original.

On success, dup() returns a new file descriptor that has the following in common with the original:

The new file descriptor is set to remain open across exec() functions.


PARAMETERS

fildes 

Is the file descriptor to duplicate.


RETURN VALUES

If successful, dup() returns a nonnegative integer; namely, the duplicated file descriptor, which is the lowest available descriptor. If failed, it returns a -1 and sets errno to the corresponding value.

EBADF 

fildes is not a valid open file descriptor.

EINTR 

A signal was caught during the dup() 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(), dup2(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), fcntl(), lockf(), open(), pipe(), socket()


PTC MKS Toolkit 10.4 Documentation Build 39.