1 .\" Copyright (c) 1980 Regents of the University of California.
2 .\" All rights reserved. The Berkeley software License Agreement
3 .\" specifies the terms and conditions for redistribution.
5 .\" @(#)dup.2 6.3 (Berkeley) 5/13/86
7 .TH DUP 2 "May 13, 1986"
10 dup, dup2 \- duplicate a descriptor
16 int dup(int \fIoldd\fP)
17 int dup2(int \fIoldd\fP, int \fInewd\fP)
20 duplicates an existing descriptor.
21 The argument \fIoldd\fP is a small non-negative integer index in
22 the per-process descriptor table. The value must be less
23 than OPEN_MAX, the size of the table.
24 The new descriptor returned by the call, let's name it
26 is the lowest numbered descriptor that is
27 not currently in use by the process.
29 The object referenced by the descriptor does not distinguish
30 between references using \fIoldd\fP and \fInewd\fP in any way.
31 Thus if \fInewd\fP and \fIoldd\fP are duplicate references to an open
37 calls all move a single pointer into the file,
38 and append mode, non-blocking I/O and asynchronous I/O options
39 are shared between the references.
40 If a separate pointer into the file is desired, a different
41 object reference to the file must be obtained by issuing an
45 The close-on-exec flag on the new file descriptor is unset.
47 In the second form of the call, the value of
49 desired is specified. If this descriptor is already
50 in use, the descriptor is first deallocated as if a
52 call had been done first.
54 is not closed if it equals
57 The value \-1 is returned if an error occurs in either call.
60 indicates the cause of the error.
69 \fInewd\fP is not a valid active descriptor
72 Too many descriptors are active.
77 are now implemented using the
81 although the old system call interfaces still exist to support old programs.