DUP2(2,L) AIX Technical Reference DUP2(2,L) ------------------------------------------------------------------------------- dup2 PURPOSE Duplicates an open file descriptor. SYNTAX int dup2 (oldfd, newfd) int oldfd, newfd; DESCRIPTION The dup2 system call duplicates the file descriptor, oldfd, to the new file descriptor, newfd. When you specify a value of newfd that is already in use, the descriptor is deallocated as if a close system call had been issued. The oldfd parameter is a small nonnegative integer index in the descriptor table. Its value must be less than the size of the descriptor table obtained by the getdtablesize subroutine. Note: Since newfd and oldfd are duplicate references to an open file once the dup2 system call has been called, the read, write, and lseek system calls move a single pointer into that file. Append mode and both non-blocking I/O and asynchronous I/O options are then shared between the references. Therefore, if you want to place a separate pointer in the file, you should issue an additional open system call to obtain a different object reference instead of using the dup2 system call. The new file descriptor is set to remain open across exec system calls. If the Transparent Computing Facility is installed, the new file descriptor is also set to remain open across rexec and run system calls. (For more information about file control, see "fcntl, flock, lockf.") RETURN VALUE When the call succeeds, a file descriptor (nonnegative integer) is returned. If the dup2 system call fails, a value of -1 is returned, and errno is set to indicate the error. ERROR CONDITIONS The dup2 system call fails if one or more of the following is true: EBADF The oldfd parameter is not a valid open file descriptor. EBADF The newfd parameter is not between 0 and 199, which is the valid range for file descriptors. Processed November 7, 1990 DUP2(2,L) 1 DUP2(2,L) AIX Technical Reference DUP2(2,L) RELATED INFORMATION In this book: "accept," "close, closex," "dup," "fcntl, flock, lockf," "getdtablesize," "open, openx, creat," "pipe," "socket," and "socketpair." Processed November 7, 1990 DUP2(2,L) 2