Go to the previous, next section.

dup and dup2

SYNOPSIS

int dup(int oldfd);

int dup2(int oldfd, int newfd);

PARAMETERS

oldfd: [in] the file descriptor to copy.

newfd: [in] the file descriptor to copy to.

DESCRIPTION

dup duplicates a file descriptor to the lowest unused file descriptor available. dup2 duplicates a file descriptor to another specified file descriptor. If the destination file descriptor is already used, it is closed. The two descriptors share all (ie. file locks, position, etc.) but the close-on-exec flag.

RETURN VALUE

The call returns the new descriptor on success. It returns -1 on error and sets errno to one of the following values: EBADF or EMFILE.

NOTE: EINVAL might well be added to the set of possible errors in the future. (Take a look in the kernel source.)

Go to the previous, next section.