


      DUP(2)                      (UNIX 5.2)                     DUP(2)



      NAME
           dup, dup2 - duplicate an open file descriptor

      SYNTAX
           int dup (fildes)
           int fildes;

           int dup2 (fildes newfildes)
           int fildes
           int newfildes

      DESCRIPTION
           Fildes is a file descriptor obtained from a creat , open ,
           dup , fcntl , or pipe system call.

           Dup and dup2 return a new file descriptor having the
           following in common with the original:

                Same open file

                Same file pointer (i.e., both file descriptors share
                one file pointer).

                Same access mode (read, write or read/write).

           The new file descriptor is set to remain open across exec
           system calls.  See fcntl (2).

           Dup returns the lowest available file descriptor.  Dup2
           closes newfildes and returns the value newfildes, which now
           refers to the same object as fildes.

           Dup and Dup2 fail if one or more of the following are true:

           [EBADF] Fildes is not a valid open file descriptor.

           [EMFILE] Twenty (20) file descriptors are currently open.

           Dup2 fails if:

           [EMFILE] newfildes is not in the range 0 to 63.

      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
           creat(2), close(2), exec(2), fcntl(2), open(2)






      Page 1                                         (73 A2 02MTA REV1)



