DUP(2)                                                     DUP(2)

     NAME
          dup - duplicate an open file descriptor

     SYNOPSIS
          #include <u.h>
          #include <libc.h>

          int dup(int oldfd, int newfd)

     DESCRIPTION
          Given a file descriptor, oldfd, referring to an open file,
          dup returns a new file descriptor referring to the same
          file.

          If newfd is -1 the system chooses the lowest available file
          descriptor.  Otherwise, dup will use newfd for the new file
          descriptor (closing any old file associated with newfd).
          File descriptors are allocated dynamically, so to prevent
          unwarranted growth of the file descriptor table, dup
          requires that newfd be no greater than 20 more than the
          highest file descriptor ever used by the program.

     SOURCE
          /sys/src/libc/9syscall

     SEE ALSO
          intro(2), dup(3)

     DIAGNOSTICS
          Sets errstr.

     Page 1                       Plan 9            (printed 12/26/24)