DUP(2) UNIX Programmer's Manual DUP(2) NAME dup, dup2 - duplicate an open file descriptor SYNOPSIS dup(fildes) int fildes; dup2(fildes, fildes2) int fildes, fildes2; DESCRIPTION Given a file descriptor returned from an _o_p_e_n, _p_i_p_e, or _c_r_e_a_t(2) call, _d_u_p allocates another file descriptor synonymous with the original. The new file descriptor is returned. In the second form of the call, _f_i_l_d_e_s is a file descriptor referring to an open file, and _f_i_l_d_e_s_2 is a non-negative integer less than the maximum value allowed for file descriptors (approximately 19). _D_u_p_2 causes _f_i_l_d_e_s_2 to refer to the same file as _f_i_l_d_e_s. If _f_i_l_d_e_s_2 already referred to an open file, it is closed first. RETURN VALUE Upon successful completion, a value of 0 is returned. Oth- erwise, a value of -1 is returned and _e_r_r_n_o is set to indi- cate the error. ERRORS _D_u_p and _d_u_p_2 will fail if: [EBADF] _F_i_l_d_e_s _o_r _f_i_l_d_e_s_2 is not a valid active descriptor. [EMFILE] Too many descriptors are active. SEE ALSO close(2), creat(2), open(2), pipe(2) ASSEMBLER (dup = 41.) (file descriptor in r0) (new file descriptor in r1) sys dup (file descriptor in r0) The _d_u_p_2 entry is implemented by adding 0100 to _f_i_l_d_e_s. Printed 5/23/83 1