Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ dup2(2) — UTek 3.0

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

accept(2)

close(2)

getdtablesize(2)

open(2)

pipe(2)

socket(2)

socketpair(2)



DUP(2)                  COMMAND REFERENCE                  DUP(2)



NAME
     dup, dup2 - duplicate a descriptor

SYNOPSIS
     newfd = dup(oldfd)
     int newfd, oldfd;

     newfd = dup2(oldfd, newfd)
     int oldfd, newfd;

DESCRIPTION
     Dup duplicates an existing object descriptor.  The argument
     oldfd is a small non-negative integer index in the per-
     process descriptor table.  The value must be less than the
     size of the table, which is returned by getdtablesize(2).
     The new descriptor newfd returned by the call is the lowest
     numbered descriptor which is not currently in use by the
     process.

     The object referenced by the descriptor does not distinguish
     between references using oldfd and newfd in any way.  Thus
     if newfd and oldfd are duplicate references to an open file,
     read(2), write(2) and lseek(2) calls all move a single
     pointer into the file.  If a separate pointer into the file
     is desired, a different object reference to the file must be
     obtained by issuing an additional open(2) call.

     In the second form of the call, the value of newfd desired
     is specified.  If this descriptor is already in use, the
     descriptor is first deallocated as if a close(2) call had
     been done first.

DIAGNOSTICS
     Dup and dup2 fail if:

     [EBADF]      Oldfd or newfd is not a valid active
                  descriptor.

     [EMFILE]     NOFILE (defined in <sys/max.h>) descriptors are
                  already active.

RETURN VALUE
     Upon successful completion, dup and dup2 return the new file
     descriptor in newfd.  Otherwise, a value of -1 is returned
     and errno is set to indicate the error.

SEE ALSO
     accept(2), close(2), getdtablesize(2), open(2), pipe(2),
     socket(2), and socketpair(2).






Printed 5/12/88                                                 1





































































%%index%%
na:216,86;
sy:302,883;
de:1185,1342;
di:2527,427;
rv:2954,389;
se:3343,289;
%%index%%000000000109

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026