DUP2(2) — HP-UX
NAME
dup2 − duplicate an open file descriptor to a specific slot
SYNOPSIS
int dup2(fildes, fildes2)
int fildes, fildes2;
REMARKS
This facility is provided for backwards compatability with Version 7 and BSD systems. Fcntl should be used for all new code.
DESCRIPTION
Fildes is a file descriptor obtained from a creat, open, dup, fcntl, or pipe system call. Fildes2 is a non-negative integer less than the maximum value allowed for file descriptors. Dup2 causes fildes2 to refer to the same file as fildes. If fildes2 already referred to an open file, it is closed first. The file descriptor returned by dup2 has the following in common with the original:
Same open file (or pipe).
Same file pointer (i.e., both file descriptors share one file pointer.)
Same access mode (read, write or read/write).
Same file status flags (see fcntl(2), F_DUPFD).
The new file descriptor is set to remain open across exec system calls. See fcntl(2).
This call can be accessed by giving either (for Version 7) the -lV7 or (for 4.1 or 4.2bsd) the -lBSD option to ld(1).
ERRORS
Dup2 will fail if one or more of the following are true:
[EBADF] Fildes is not a valid open file descriptor.
[EINVAL] Fildes2 is not in the range of legal file descriptors.
RETURN VALUE
Upon successful completion a non-negative integer, namely the file descriptor, is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
SEE ALSO
close(2), creat(2), dup(2), exec(2), fcntl(2), open(2), pipe(2).
Hewlett-Packard Company — Version B.1, April 12, 1993